From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 62326C3DA4A for ; Tue, 30 Jul 2024 01:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SpLxUbenjvM5d5qBB7kCuthLr1OMeOtBCRFWHq7ibaU=; b=ghSo4/cZFhafvURSMDfKmLrow/ LE5Pud1z7nlMa07Hi6cho2BC0/b/qBNn98yJ4oXXfTElD4UUsu/9l6XUm+4p6x/AzehTKzmB8yD4o mWPmTbZuwgZp/xnTkip+qegaf4IyYg7uwUHtuAfN/HM2fnx+9HTQXXl1eQYPscYNqoB5TDPxrHEZO 7stpqwPlR4ja8lQ2cAo4/gzVzoVrbjF59/AD53dR6qzpRP5+yASp+aWlBEbUA/uGxnNCluzHL1ALH qCIzNDWzicCaT4JR3BYoVVnEAVghbxbkS3925coY9uEdWm1gO8ZKoFywjfcXA/8umcn1pdqThMJGr B+slg4cQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYbnl-0000000DFgm-1Bpo; Tue, 30 Jul 2024 01:37:21 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYbnI-0000000DFat-2sKs for linux-arm-kernel@lists.infradead.org; Tue, 30 Jul 2024 01:36:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722303410; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SpLxUbenjvM5d5qBB7kCuthLr1OMeOtBCRFWHq7ibaU=; b=EYJYo6jwnWSccq6D5I2WoUlpuSdyUVTQKCE2CeZT6nXVAG/DqB7HS+VbLK+ygDeex8wR08 0qq6cwSpDZl7BMFMfJgSW5stEQlK5cHK+TztHCvNK8yKFlw/7xJ4tgo8PUMKHQOSfNJ3Uv y5NuocMswI41yJFXKwJ8kIZUahWaBIQ= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-286-ZJqvYr05PuC6L6yyTHT5bA-1; Mon, 29 Jul 2024 21:36:49 -0400 X-MC-Unique: ZJqvYr05PuC6L6yyTHT5bA-1 Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-1fee7c9e4a4so26953445ad.2 for ; Mon, 29 Jul 2024 18:36:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722303408; x=1722908208; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SpLxUbenjvM5d5qBB7kCuthLr1OMeOtBCRFWHq7ibaU=; b=HtLehgEaTvuSVPksKQbY9ky1SouNesU8BrG8Km0mPiOJSm9SVBUUT8aPhVFC1khrzV 0K4f8rLAVeBBrT2eZsCp/S0y5KDQqXsh3X/L8FQ1Pud5eMYy4ZKjVZ/JJQ216NgTq5/8 8q9CPoEXVWkFF8PS+pH4lRQIpO9j6RkM3g9lFThrVVAWKQqPVPRSTr1AFienb7GFHfxH pfj6VJI80FzRYCXBawHQaa1sUikPb+RIn5efwZpHAuNslvIdNe9j/cDd6kd9QALgKI7/ euR1AbvsUJ2+KBZJ6VP/HiEvzo8KN+dNpPHL3lBy78grm+Z6kaWOtAfSFmldjAI/Keb1 K5Cg== X-Forwarded-Encrypted: i=1; AJvYcCU1wQY3fPDoB24pbMq95a6cJYErPdBDFzQltThbkHF2cWbsPfOOjzRo/1TGWETEcICfuCQqamaiF5s1FI0P9TuR6RbT5AOn1oeWiaiEpRSLIFfsxFM= X-Gm-Message-State: AOJu0YwW23QMUnghqd4xpdG9jeC3luXIz9vb4KLuz2YH6Db6k2zQwpcA PxMECxwEYCXoRVJQrh2OUJ8VBMWAPiAPy4uAsn3AsTfGUgmRM6Fkmxrpo5T/Vds7vmVjDJI7eD6 yZ5XTp/Q7f/9C41p27LQ+2Ek/xPL/T9hiNol4SQ5ihzOYxTsejhQz9BzWRvZVXhHZJqDNIaan X-Received: by 2002:a17:902:f60d:b0:1fb:8245:fdeb with SMTP id d9443c01a7336-1ff048933edmr77628935ad.64.1722303408129; Mon, 29 Jul 2024 18:36:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPZMHMDXUZj1wSKwoNk+BDcdLLq2tHyZJH4+Sq/yqo8hZECliTBNIBT1SO3Bu0fym/xIh85g== X-Received: by 2002:a17:902:f60d:b0:1fb:8245:fdeb with SMTP id d9443c01a7336-1ff048933edmr77628845ad.64.1722303407818; Mon, 29 Jul 2024 18:36:47 -0700 (PDT) Received: from [192.168.68.54] ([43.252.112.134]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff23ff5997sm28209945ad.267.2024.07.29.18.36.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Jul 2024 18:36:46 -0700 (PDT) Message-ID: Date: Tue, 30 Jul 2024 11:36:38 +1000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 05/15] arm64: Mark all I/O as non-secure shared To: Steven Price , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni References: <20240701095505.165383-1-steven.price@arm.com> <20240701095505.165383-6-steven.price@arm.com> From: Gavin Shan In-Reply-To: <20240701095505.165383-6-steven.price@arm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_183652_835405_62987B08 X-CRM114-Status: GOOD ( 19.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 7/1/24 7:54 PM, Steven Price wrote: > All I/O is by default considered non-secure for realms. As such > mark them as shared with the host. > > Co-developed-by: Suzuki K Poulose > Signed-off-by: Suzuki K Poulose > Signed-off-by: Steven Price > --- > Changes since v3: > * Add PROT_NS_SHARED to FIXMAP_PAGE_IO rather than overriding > set_fixmap_io() with a custom function. > * Modify ioreamp_cache() to specify PROT_NS_SHARED too. > --- > arch/arm64/include/asm/fixmap.h | 2 +- > arch/arm64/include/asm/io.h | 8 ++++---- > 2 files changed, 5 insertions(+), 5 deletions(-) > I'm unable to understand this. Steven, could you please explain a bit how PROT_NS_SHARED is turned to a shared (non-secure) mapping to hardware? According to tf-rmm's implementation in tf-rmm/lib/s2tt/src/s2tt_pvt_defs.h, a shared (non-secure) mapping is is identified by NS bit (bit#55). I find difficulties how the NS bit is correlate with PROT_NS_SHARED. For example, how the NS bit is set based on PROT_NS_SHARED. > diff --git a/arch/arm64/include/asm/fixmap.h b/arch/arm64/include/asm/fixmap.h > index 87e307804b99..f2c5e653562e 100644 > --- a/arch/arm64/include/asm/fixmap.h > +++ b/arch/arm64/include/asm/fixmap.h > @@ -98,7 +98,7 @@ enum fixed_addresses { > #define FIXADDR_TOT_SIZE (__end_of_fixed_addresses << PAGE_SHIFT) > #define FIXADDR_TOT_START (FIXADDR_TOP - FIXADDR_TOT_SIZE) > > -#define FIXMAP_PAGE_IO __pgprot(PROT_DEVICE_nGnRE) > +#define FIXMAP_PAGE_IO __pgprot(PROT_DEVICE_nGnRE | PROT_NS_SHARED) > > void __init early_fixmap_init(void); > > diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h > index 4ff0ae3f6d66..07fc1801c6ad 100644 > --- a/arch/arm64/include/asm/io.h > +++ b/arch/arm64/include/asm/io.h > @@ -277,12 +277,12 @@ static inline void __const_iowrite64_copy(void __iomem *to, const void *from, > > #define ioremap_prot ioremap_prot > > -#define _PAGE_IOREMAP PROT_DEVICE_nGnRE > +#define _PAGE_IOREMAP (PROT_DEVICE_nGnRE | PROT_NS_SHARED) > > #define ioremap_wc(addr, size) \ > - ioremap_prot((addr), (size), PROT_NORMAL_NC) > + ioremap_prot((addr), (size), (PROT_NORMAL_NC | PROT_NS_SHARED)) > #define ioremap_np(addr, size) \ > - ioremap_prot((addr), (size), PROT_DEVICE_nGnRnE) > + ioremap_prot((addr), (size), (PROT_DEVICE_nGnRnE | PROT_NS_SHARED)) > > /* > * io{read,write}{16,32,64}be() macros > @@ -303,7 +303,7 @@ static inline void __iomem *ioremap_cache(phys_addr_t addr, size_t size) > if (pfn_is_map_memory(__phys_to_pfn(addr))) > return (void __iomem *)__phys_to_virt(addr); > > - return ioremap_prot(addr, size, PROT_NORMAL); > + return ioremap_prot(addr, size, PROT_NORMAL | PROT_NS_SHARED); > } > > /* Thanks, Gavin