Skip to content

Commit

Permalink
OvmfPkg/IoMmuDxe: Provide an implementation for SetAttribute
Browse files Browse the repository at this point in the history
A recent change to the PciIoMap() function now propagates the return code
from the IoMmu protocol SetAttribute() operation. The implementation of
this operation in OvmfPkg/IoMmuDxe/CcIoMmu.c returns EFI_UNSUPPORTED,
resulting in a failure to boot the guest.

Provide an implementation for SetAttribute() that validates the IoMmu
access method being requested against the IoMmu mapping operation.

Suggested-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Message-Id: <c0f9e95f557b601a045da015c1a97201e8aec2ab.1706634932.git.thomas.lendacky@amd.com>
Tested-by: Min Xu <min.m.xu@intel.com>
Reviewed-by: Min Xu <min.m.xu@intel.com>
  • Loading branch information
tlendacky authored and mergify[bot] committed Jan 31, 2024
1 parent 0e9b124 commit 97c3f5b
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions OvmfPkg/IoMmuDxe/CcIoMmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
operations must be performed on unencrypted buffer hence we use a bounce
buffer to map the guest buffer into an unencrypted DMA buffer.
Copyright (c) 2017, AMD Inc. All rights reserved.<BR>
Copyright (c) 2017 - 2024, AMD Inc. All rights reserved.<BR>
Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand Down Expand Up @@ -751,7 +751,58 @@ IoMmuSetAttribute (
IN UINT64 IoMmuAccess
)
{
return EFI_UNSUPPORTED;
MAP_INFO *MapInfo;
EFI_STATUS Status;

DEBUG ((DEBUG_VERBOSE, "%a: Mapping=0x%p Access=%lu\n", __func__, Mapping, IoMmuAccess));

if (Mapping == NULL) {
return EFI_INVALID_PARAMETER;
}

Status = EFI_SUCCESS;

//
// An IoMmuAccess value of 0 is always accepted, validate any non-zero value.
//
if (IoMmuAccess != 0) {
MapInfo = (MAP_INFO *)Mapping;

//
// The mapping operation already implied the access mode. Validate that
// the supplied access mode matches operation access mode.
//
switch (MapInfo->Operation) {
case EdkiiIoMmuOperationBusMasterRead:
case EdkiiIoMmuOperationBusMasterRead64:
if (IoMmuAccess != EDKII_IOMMU_ACCESS_READ) {
Status = EFI_INVALID_PARAMETER;
}

break;

case EdkiiIoMmuOperationBusMasterWrite:
case EdkiiIoMmuOperationBusMasterWrite64:
if (IoMmuAccess != EDKII_IOMMU_ACCESS_WRITE) {
Status = EFI_INVALID_PARAMETER;
}

break;

case EdkiiIoMmuOperationBusMasterCommonBuffer:
case EdkiiIoMmuOperationBusMasterCommonBuffer64:
if (IoMmuAccess != (EDKII_IOMMU_ACCESS_READ | EDKII_IOMMU_ACCESS_WRITE)) {
Status = EFI_INVALID_PARAMETER;
}

break;

default:
Status = EFI_UNSUPPORTED;
}
}

return Status;
}

EDKII_IOMMU_PROTOCOL mIoMmu = {
Expand Down

0 comments on commit 97c3f5b

Please sign in to comment.