From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f198.google.com (mail-pf0-f198.google.com [209.85.192.198]) by kanga.kvack.org (Postfix) with ESMTP id EAB716B0038 for ; Tue, 28 Feb 2017 18:20:00 -0500 (EST) Received: by mail-pf0-f198.google.com with SMTP id u62so29922131pfk.1 for ; Tue, 28 Feb 2017 15:20:00 -0800 (PST) Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0052.outbound.protection.outlook.com. [104.47.40.52]) by mx.google.com with ESMTPS id s75si2974687pgs.53.2017.02.28.15.19.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Feb 2017 15:19:59 -0800 (PST) Subject: Re: [RFC PATCH v4 19/28] swiotlb: Add warnings for use of bounce buffers with SME References: <20170216154158.19244.66630.stgit@tlendack-t1.amdoffice.net> <20170216154619.19244.76653.stgit@tlendack-t1.amdoffice.net> <20170227175259.whl75utazbzxp7jo@pd.tnic> From: Tom Lendacky Message-ID: <9b5af67b-0969-5402-cc01-3ea98f41b748@amd.com> Date: Tue, 28 Feb 2017 17:19:51 -0600 MIME-Version: 1.0 In-Reply-To: <20170227175259.whl75utazbzxp7jo@pd.tnic> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Borislav Petkov Cc: linux-arch@vger.kernel.org, linux-efi@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, iommu@lists.linux-foundation.org, Rik van Riel , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Toshimitsu Kani , Arnd Bergmann , Jonathan Corbet , Matt Fleming , "Michael S. Tsirkin" , Joerg Roedel , Konrad Rzeszutek Wilk , Paolo Bonzini , Brijesh Singh , Ingo Molnar , Alexander Potapenko , Andy Lutomirski , "H. Peter Anvin" , Andrey Ryabinin , Thomas Gleixner , Larry Woodman , Dmitry Vyukov On 2/27/2017 11:52 AM, Borislav Petkov wrote: > On Thu, Feb 16, 2017 at 09:46:19AM -0600, Tom Lendacky wrote: >> Add warnings to let the user know when bounce buffers are being used for >> DMA when SME is active. Since the bounce buffers are not in encrypted >> memory, these notifications are to allow the user to determine some >> appropriate action - if necessary. >> >> Signed-off-by: Tom Lendacky >> --- >> arch/x86/include/asm/mem_encrypt.h | 11 +++++++++++ >> include/linux/dma-mapping.h | 11 +++++++++++ >> include/linux/mem_encrypt.h | 6 ++++++ >> lib/swiotlb.c | 3 +++ >> 4 files changed, 31 insertions(+) >> >> diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h >> index 87e816f..5a17f1b 100644 >> --- a/arch/x86/include/asm/mem_encrypt.h >> +++ b/arch/x86/include/asm/mem_encrypt.h >> @@ -26,6 +26,11 @@ static inline bool sme_active(void) >> return (sme_me_mask) ? true : false; >> } >> >> +static inline u64 sme_dma_mask(void) >> +{ >> + return ((u64)sme_me_mask << 1) - 1; >> +} >> + >> void __init sme_early_encrypt(resource_size_t paddr, >> unsigned long size); >> void __init sme_early_decrypt(resource_size_t paddr, >> @@ -53,6 +58,12 @@ static inline bool sme_active(void) >> { >> return false; >> } >> + >> +static inline u64 sme_dma_mask(void) >> +{ >> + return 0ULL; >> +} >> + >> #endif >> >> static inline void __init sme_early_encrypt(resource_size_t paddr, >> diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h >> index 10c5a17..130bef7 100644 >> --- a/include/linux/dma-mapping.h >> +++ b/include/linux/dma-mapping.h >> @@ -10,6 +10,7 @@ >> #include >> #include >> #include >> +#include >> >> /** >> * List of possible attributes associated with a DMA mapping. The semantics >> @@ -557,6 +558,11 @@ static inline int dma_set_mask(struct device *dev, u64 mask) >> >> if (!dev->dma_mask || !dma_supported(dev, mask)) >> return -EIO; >> + >> + if (sme_active() && (mask < sme_dma_mask())) >> + dev_warn(dev, >> + "SME is active, device will require DMA bounce buffers\n"); >> + > > Yes, definitely _once() here. Setting the mask is a probe/init type event, so I think not having the _once() would be better so that all devices that set a mask to something less than the SME encryption mask would be identified. This isn't done for every DMA, etc. > > It could be extended later to be per-device if the need arises. > > Also, a bit above in this function, we test if (ops->set_dma_mask) so > device drivers which supply even an empty ->set_dma_mask will circumvent > this check. > > It probably doesn't matter all that much right now because the > only driver I see right now defining this method, though, is > ethernet/intel/fm10k/fm10k_pf.c and some other arches' functionality > which is unrelated here. Device drivers don't supply set_dma_mask() since that is part of the dma_map_ops structure. The fm10k_pf.c file function is unrelated to this (it's part of an internal driver structure). The dma_map_ops structure is setup by the arch or an iommu. Thanks, Tom > > But still... > > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org