Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2781505pxj; Mon, 31 May 2021 10:35:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6uSlQjqUi8z1MvDNWhBshRSdPW5SIiXygSW+2+Len5yY2RD5+DiAeXS3kCp7Z2BljWdI9 X-Received: by 2002:a92:ced1:: with SMTP id z17mr5994911ilq.292.1622482543440; Mon, 31 May 2021 10:35:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622482543; cv=none; d=google.com; s=arc-20160816; b=ooT4H9sRYp11GS/x6Nl2UJt2U0fVRLUAWGvi62aLgA4r+QeT1eBECbWnhYmX9vT8C9 qe+drQD4nzxJaCXKmHOstW1wT2maXpZMoGB7aW2gqnAKpruDC7LF/xmLpIDCRSwuT84a 0X2ALGVsDkBd58cDtQN/kP9al6a5xXTt8aZDwOpG0kNTvP7QoH60qVkN546CgJGNcZtJ +TXilqioarnOjHO9l1nlhk9jpkdwO3BXjXwKooK30WlXs7HRsiWgY9pWqbEXjtpzO3TI G23bxa/ofUkJOaHgz/ncK+QcMUX/9Xm45cpRol/lhGReDGda1aJQPCnMfoEhS79Fn0Zv qhOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:ironport-sdr:ironport-sdr; bh=f4FZ8YCmJaS/FZpmKeEaF3B+DSnshVkQwfNAK+4o8b0=; b=CiscTJsA1m20Ya259ZFih5oqrNbdxAhr8+n0bKIj3+tQ1MSgM3vW5l36bNNV6DBbin 5X73i4z6t/v9iAr3zIQgdnp8+KUUWKtxHyu3pBtn1psHLpSrQKeay5ELhePGdP7pfBeZ uq9V+MmyLDMHW+6HVAN5ajwqCryb9vcVbloP9sQjbqs6jXx4OqTw16DhwZ1YucYykFix /RRUWyVEjHfaFDuvrcghqK33d5c97jo7Zvlb4IC6U/pJzhKESpvT8fGv8+GbXB9Salhk Cg4DDKwd5a7oetNSXS6+SsQfwhxxBFSGEDX1oThyJZFXxXSFgqi7mhI4EQWwZf2ynBAH psNw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w8si15349447jaw.8.2021.05.31.10.35.28; Mon, 31 May 2021 10:35:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233329AbhEaRev (ORCPT + 99 others); Mon, 31 May 2021 13:34:51 -0400 Received: from mga02.intel.com ([134.134.136.20]:54132 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233384AbhEaRe2 (ORCPT ); Mon, 31 May 2021 13:34:28 -0400 IronPort-SDR: p1i2PqwCpfT4ZLeiyT7MvjltxJtFc91b0IFpvdy7Fvjcaygxj6DlBHra7VZvRwsDECUpEKJSnH NQaVpeQWYIpg== X-IronPort-AV: E=McAfee;i="6200,9189,10001"; a="190508158" X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="190508158" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2021 10:32:48 -0700 IronPort-SDR: 1vlLnX9MYXFLxiXoYRE+zmueK4JDBB/5KtsS1mO++zvAUwWZ8UUhq7bvOTR5ORy8O7qTQzXVjE u74VxzV4hPCg== X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="616588635" Received: from unknown (HELO skuppusw-mobl5.amr.corp.intel.com) ([10.251.152.221]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2021 10:32:47 -0700 Subject: Re: [RFC v2 28/32] x86/tdx: Make pages shared in ioremap() To: Borislav Petkov Cc: Tom Lendacky , Sean Christopherson , Dave Hansen , Andi Kleen , Peter Zijlstra , Andy Lutomirski , Dan Williams , Tony Luck , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Raj Ashok , linux-kernel@vger.kernel.org, Brijesh Singh References: <797c95bf-9516-8aee-59d0-f5259d77bb75@linux.intel.com> <5b4b4fc0-aaa8-3407-6602-537d59572bc1@intel.com> <0e233779-9c10-11df-b527-ef61e003ea35@linux.intel.com> <86b4d995-9619-81fa-5ef4-86f48ab01e96@amd.com> From: "Kuppuswamy, Sathyanarayanan" Message-ID: <96a63ddf-98f9-7095-f7bb-100bf56a4d10@linux.intel.com> Date: Mon, 31 May 2021 10:32:44 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/31/21 8:13 AM, Borislav Petkov wrote: > On Tue, May 25, 2021 at 11:21:21AM -0700, Kuppuswamy, Sathyanarayanan wrote: >> Following is the sample implementation. Please let me know your >> comments. > > Doesn't look like what I suggested here: > > https://lkml.kernel.org/r/YKfPLlulaqwypNkO@zn.tnic IIUC, following are your design suggestions: 1. Define generic flags. I think following flags are defined as you have suggested. +++ b/include/linux/protected_guest.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _LINUX_PROTECTED_GUEST_H +#define _LINUX_PROTECTED_GUEST_H 1 + +/* Protected Guest Feature Flags (leave 0-0xff for arch specific flags) */ + +/* Support for guest encryption */ +#define VM_MEM_ENCRYPT 0x100 +/* Encryption support is active */ +#define VM_MEM_ENCRYPT_ACTIVE 0x101 +/* Support for unrolled string IO */ +#define VM_UNROLL_STRING_IO 0x102 +/* Support for host memory encryption */ +#define VM_HOST_MEM_ENCRYPT 0x103 2. Define generic functions and allow calls to arch specific implementations. For above requirement, instead of calling arch specific functions from include/linux/protected_guest.h, I have directly included the arch specific file in linux/protected_guest.h +#ifdef CONFIG_ARCH_HAS_PROTECTED_GUEST +#include +#else +static inline bool is_protected_guest(void) { return false; } +static inline bool protected_guest_has(unsigned long flag) { return false; } +#endif 3. Implement arch specific implementations respond to protected_guest_has() calls right? I think above requirement is satisfied in following implementation. +++ b/arch/x86/include/asm/protected_guest.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2020 Intel Corporation */ +#ifndef _ASM_PROTECTED_GUEST +#define _ASM_PROTECTED_GUEST 1 + +#include +#include + +/* Only include through linux/protected_guest.h */ + +static inline bool is_protected_guest(void) +{ + return boot_cpu_has(X86_FEATURE_TDX_GUEST); +} + +static inline bool protected_guest_has(unsigned long flag) +{ + if (boot_cpu_has(X86_FEATURE_TDX_GUEST)) + return tdx_protected_guest_has(flag); + + return false; +} + Did I misunderstand anything ? Please let me know your comments. > -- Sathyanarayanan Kuppuswamy Linux Kernel Developer