Add mlx5_is_adversarial() to report whether the driver treats the NIC as untrusted. In a confidential computing guest, the hypervisor and any passthrough device are outside the guest's trust boundary, so the mode is derived from cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT) when the PCI function is probed. An SF inherits the mode of its parent function. This turns adversarial mode on automatically in such guests, without any administrator configuration. Reviewed-by: Tariq Toukan Reviewed-by: Dragos Tatulea Signed-off-by: Yishai Hadas --- drivers/net/ethernet/mellanox/mlx5/core/main.c | 9 +++++++++ drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c | 1 + include/linux/mlx5/driver.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c index 1a45474ce03d..0fee5db2b1d8 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c @@ -31,6 +31,7 @@ */ #include +#include #include #include #include @@ -484,6 +485,12 @@ bool mlx5_is_roce_on(struct mlx5_core_dev *dev) } EXPORT_SYMBOL(mlx5_is_roce_on); +bool mlx5_is_adversarial(struct mlx5_core_dev *dev) +{ + return dev->adv_mode; +} +EXPORT_SYMBOL_GPL(mlx5_is_adversarial); + static int handle_hca_cap_2(struct mlx5_core_dev *dev, void *set_ctx) { bool do_set = false; @@ -1961,6 +1968,8 @@ static int probe_one(struct pci_dev *pdev, const struct pci_device_id *id) goto adev_init_err; } + dev->adv_mode = cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT); + err = mlx5_mdev_init(dev, prof_sel); if (err) goto mdev_init_err; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c index 4391ef0bab5d..90c6c99d1f07 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c @@ -40,6 +40,7 @@ static int mlx5_sf_dev_probe(struct auxiliary_device *adev, const struct auxilia mdev->coredev_type = MLX5_COREDEV_SF; mdev->priv.parent_mdev = sf_dev->parent_mdev; mdev->priv.adev_idx = adev->id; + mdev->adv_mode = sf_dev->parent_mdev->adv_mode; sf_dev->mdev = mdev; /* Only local SFs do light probe */ diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index a527a0795bee..517c55314b95 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -810,6 +810,7 @@ struct mlx5_core_dev { struct mutex wc_state_lock; struct devlink *shd; struct mlx5_data_direct *data_direct; + bool adv_mode; }; struct mlx5_db { @@ -1336,6 +1337,7 @@ enum { }; bool mlx5_is_roce_on(struct mlx5_core_dev *dev); +bool mlx5_is_adversarial(struct mlx5_core_dev *dev); static inline bool mlx5_get_roce_state(struct mlx5_core_dev *dev) { -- 2.18.1