Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1166365pxb; Fri, 21 Jan 2022 11:15:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJwZV6FWMwHVwa6vUnGdtM6ggUW51cZGarKU62LX21zDC920Ufasd6IOfzpNXhRSJfr89LJS X-Received: by 2002:a63:3710:: with SMTP id e16mr3907995pga.507.1642792541730; Fri, 21 Jan 2022 11:15:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642792541; cv=none; d=google.com; s=arc-20160816; b=rxImP9x67x2qDsmW7eDnluMHx+5O88r1E+dmd0uygc3h/4p3rbZA+qAB4SriNcTJ0n 7O+Pvjwa+m2JmTOeBmit8Wlvo+MureBYts3u4f0MVhuQdJvj5rcfwBu4vD3ndvc6HB2d RDLYC//mhmN7lhlPLX//X+3CGo62DEJscRxAzl+6D+vwi/tWep2X4oINGRacrYgURlSt TFG6xyn8hIXTc9L2yV2tIgPEV1SdCx+ncEQCBYXS/2e+DT/ufBKMn4fFT8h9JMkUAcyv D7GZAreIXNXkKJXtCz9k18Lsnm1o3ZLDL+fqPMfyUpSVzrj6jk5FZOc95Xq3ktGYDjjj biAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BNGvzXGl/y0GbmZJgEe+t3c2zavYEGr3Ohli9ZTv3qU=; b=nwxao9TX6VlkqHL2TQnXSKxnbdMLTNkeea36wdqLAL2lg1BQbuuex5mVwpdFgibA6M cU2c/ETR5kx8e1DmbIKAc2mwx1n1lxplXvrl241FiLprzZiNjVTr5WrYf/C8T6H44+vO 2sjv16PNf+STKt80bv5i/zb+cw9PhuQwITMew3nbzpiHUYe5fHvuq83Xw+IBJSEDPz24 uA9wIdURI6xbTjdqFjs0bKDKBIUtqI+Cw7cFfgttObZP13TmyISUswuL+1goMXTy5gco waYmTvCO0W6MA1gwXoV0eBvc/+4hCxjymVwuIJWGObPCC1EnXYLKKIOkwbwjHiWlp52j /8Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=PGQe7g9+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u14si8392160ple.464.2022.01.21.11.15.29; Fri, 21 Jan 2022 11:15:41 -0800 (PST) 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; dkim=pass header.i=@alien8.de header.s=dkim header.b=PGQe7g9+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354860AbiASNfY (ORCPT + 99 others); Wed, 19 Jan 2022 08:35:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238516AbiASNfV (ORCPT ); Wed, 19 Jan 2022 08:35:21 -0500 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B827C06161C for ; Wed, 19 Jan 2022 05:35:21 -0800 (PST) Received: from zn.tnic (dslb-088-067-202-008.088.067.pools.vodafone-ip.de [88.67.202.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id B91271EC01A9; Wed, 19 Jan 2022 14:35:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1642599315; 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:in-reply-to:in-reply-to: references:references; bh=BNGvzXGl/y0GbmZJgEe+t3c2zavYEGr3Ohli9ZTv3qU=; b=PGQe7g9+fK2wO3nnqpEKLhnjgfeB0YDXKsYHahlQeGjJ6uQm4UCjAdlxYcl1t+P2Du8LNv SVebiSGevl/ZLy0iARZZV8WwBUHIWcTh9yNINLJ6raSCHUNcStrh9Ci0D0oM1/2BaAr/YP qHrNjF9pkciv86/QNNJ/7EKnLcfOjX8= Date: Wed, 19 Jan 2022 14:35:09 +0100 From: Borislav Petkov To: "Kirill A. Shutemov" , "H. Peter Anvin" , Thomas Gleixner Cc: "Kirill A. Shutemov" , mingo@redhat.com, dave.hansen@intel.com, luto@kernel.org, peterz@infradead.org, sathyanarayanan.kuppuswamy@linux.intel.com, aarcange@redhat.com, ak@linux.intel.com, dan.j.williams@intel.com, david@redhat.com, hpa@zytor.com, jgross@suse.com, jmattson@google.com, joro@8bytes.org, jpoimboe@redhat.com, knsathya@kernel.org, pbonzini@redhat.com, sdeep@vmware.com, seanjc@google.com, tony.luck@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 10/26] x86/tdx: Support TDX guest port I/O at decompression time Message-ID: References: <20211214150304.62613-1-kirill.shutemov@linux.intel.com> <20211214150304.62613-11-kirill.shutemov@linux.intel.com> <20220115010155.ss2hnyotw4a3nljf@black.fi.intel.com> <20220117143920.3umnnlx7dl27cm5z@box.shutemov.name> <20220119115326.rw2aj3ho2mct4xxv@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220119115326.rw2aj3ho2mct4xxv@box.shutemov.name> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Raise hpa and tglx to To: for the general direction. Full mail is at https://lore.kernel.org/r/20220119115326.rw2aj3ho2mct4xxv@box.shutemov.name On Wed, Jan 19, 2022 at 02:53:26PM +0300, Kirill A. Shutemov wrote: > Could you take a look if the diff below is the right direction? > > If yes, I will prepare a proper patches. My plan is 3 patches: introduce > , add 'struct port_io_ops' for early boot, hook up > alternative 'struct port_io_ops' for TDX. Makes sense. > diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h > index 34c9dbb6a47d..27ce7cef13aa 100644 > --- a/arch/x86/boot/boot.h > +++ b/arch/x86/boot/boot.h > @@ -18,11 +18,14 @@ > > #ifndef __ASSEMBLY__ > > +#undef CONFIG_PARAVIRT Yeah, this is the stuff I'd like to avoid in boot/. Can we get rid of any ifdeffery in the shared/ namespace? I see this slow_down_io()-enforced CONFIG_PARAVIRT ifdeffery and that should not be there but in the ...asm/io.h kernel proper header. In the shared header we should have only basic functions which are shared by all. For the same reason I don't think the shared header should have those if (cc_platform_has... branches but just the basic bits with the asm wrappers. Hmmm. > diff --git a/arch/x86/boot/compressed/io.h b/arch/x86/boot/compressed/io.h > new file mode 100644 > index 000000000000..e69de29bb2d1 That one's empty. > diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c > index d8373d766672..48de56f2219d 100644 > --- a/arch/x86/boot/compressed/misc.c > +++ b/arch/x86/boot/compressed/misc.c > @@ -15,9 +15,12 @@ > #include "misc.h" > #include "error.h" > #include "pgtable.h" > +#include "tdx.h" > +#include "io.h" > #include "../string.h" > #include "../voffset.h" > #include > +#include > > /* > * WARNING!! > @@ -47,6 +50,8 @@ void *memmove(void *dest, const void *src, size_t n); > */ > struct boot_params *boot_params; > > +struct port_io_ops port_io_ops; call that pio_ops to differ from the struct name. > + > memptr free_mem_ptr; > memptr free_mem_end_ptr; > > @@ -103,10 +108,12 @@ static void serial_putchar(int ch) > { > unsigned timeout = 0xffff; > > - while ((inb(early_serial_base + LSR) & XMTRDY) == 0 && --timeout) > + while ((port_io_ops.inb(early_serial_base + LSR) & XMTRDY) == 0 && > + --timeout) { > cpu_relax(); > + } > > - outb(ch, early_serial_base + TXR); > + port_io_ops.outb(ch, early_serial_base + TXR); > } > > void __putstr(const char *s) > @@ -152,10 +159,10 @@ void __putstr(const char *s) > boot_params->screen_info.orig_y = y; > > pos = (x + cols * y) * 2; /* Update cursor position */ > - outb(14, vidport); > - outb(0xff & (pos >> 9), vidport+1); > - outb(15, vidport); > - outb(0xff & (pos >> 1), vidport+1); > + port_io_ops.outb(14, vidport); > + port_io_ops.outb(0xff & (pos >> 9), vidport+1); > + port_io_ops.outb(15, vidport); > + port_io_ops.outb(0xff & (pos >> 1), vidport+1); > } > > void __puthex(unsigned long value) > @@ -370,6 +377,15 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap, > lines = boot_params->screen_info.orig_video_lines; > cols = boot_params->screen_info.orig_video_cols; > > + port_io_ops = (const struct port_io_ops){ > + .inb = inb, > + .inw = inw, > + .inl = inl, > + .outb = outb, > + .outw = outw, > + .outl = outl, > + }; Why here and not statically defined above? > + > /* > * Detect TDX guest environment. > * > diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h > index 6502adf71a2f..74951befb240 100644 > --- a/arch/x86/boot/compressed/misc.h > +++ b/arch/x86/boot/compressed/misc.h > @@ -19,26 +19,23 @@ > /* cpu_feature_enabled() cannot be used this early */ > #define USE_EARLY_PGTABLE_L5 > > -/* > - * Redefine __in/__out macros via tdx.h before including > - * linux/io.h. > - */ > -#include "tdx.h" > - > #include > #include > #include > -#include > #include > #include > #include > #include > > +/* Avoid pulling outb()/inb() from */ > +#define _ACPI_IO_H_ > + This too. I think those shared headers should contain the basic functionality which all stages share and can include without ifdeffery. If they have to change that functionality, they will have to define their own io.h header, extend it there by using the basic one and then use it. This way we'll always have the common, shared stuff in, well, a shared header. IMNSVHO. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette