* [PATCH V5 net] net: mana: Fix MANA VF unload when hardware is unresponsive
From: Souradeep Chakrabarti @ 2023-07-05 8:16 UTC (permalink / raw)
To: kys, haiyangz, wei.liu, decui, davem, edumazet, kuba, pabeni,
longli, sharmaajay, leon, cai.huoqing, ssengar, vkuznets, tglx,
linux-hyperv, netdev, linux-kernel, linux-rdma
Cc: stable, schakrabarti, Souradeep Chakrabarti
When unloading the MANA driver, mana_dealloc_queues() waits for the MANA
hardware to complete any inflight packets and set the pending send count
to zero. But if the hardware has failed, mana_dealloc_queues()
could wait forever.
Fix this by adding a timeout to the wait. Set the timeout to 120 seconds,
which is a somewhat arbitrary value that is more than long enough for
functional hardware to complete any sends.
Fixes: ca9c54d2d6a5 ("net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)")
---
V4 -> V5:
* Added fixes tag
* Changed the usleep_range from static to incremental value.
* Initialized timeout in the begining.
---
Signed-off-by: Souradeep Chakrabarti <schakrabarti@linux.microsoft.com>
---
drivers/net/ethernet/microsoft/mana/mana_en.c | 30 ++++++++++++++++---
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
index a499e460594b..56b7074db1a2 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -2345,9 +2345,13 @@ int mana_attach(struct net_device *ndev)
static int mana_dealloc_queues(struct net_device *ndev)
{
struct mana_port_context *apc = netdev_priv(ndev);
+ unsigned long timeout = jiffies + 120 * HZ;
struct gdma_dev *gd = apc->ac->gdma_dev;
struct mana_txq *txq;
+ struct sk_buff *skb;
+ struct mana_cq *cq;
int i, err;
+ u32 tsleep;
if (apc->port_is_up)
return -EINVAL;
@@ -2363,15 +2367,33 @@ static int mana_dealloc_queues(struct net_device *ndev)
* to false, but it doesn't matter since mana_start_xmit() drops any
* new packets due to apc->port_is_up being false.
*
- * Drain all the in-flight TX packets
+ * Drain all the in-flight TX packets.
+ * A timeout of 120 seconds for all the queues is used.
+ * This will break the while loop when h/w is not responding.
+ * This value of 120 has been decided here considering max
+ * number of queues.
*/
+
for (i = 0; i < apc->num_queues; i++) {
txq = &apc->tx_qp[i].txq;
-
- while (atomic_read(&txq->pending_sends) > 0)
- usleep_range(1000, 2000);
+ tsleep = 1000;
+ while (atomic_read(&txq->pending_sends) > 0 &&
+ time_before(jiffies, timeout)) {
+ usleep_range(tsleep, tsleep << 1);
+ tsleep <<= 1;
+ }
}
+ for (i = 0; i < apc->num_queues; i++) {
+ txq = &apc->tx_qp[i].txq;
+ cq = &apc->tx_qp[i].tx_cq;
+ while (atomic_read(&txq->pending_sends)) {
+ skb = skb_dequeue(&txq->pending_skbs);
+ mana_unmap_skb(skb, apc);
+ dev_consume_skb_any(skb);
+ atomic_sub(1, &txq->pending_sends);
+ }
+ }
/* We're 100% sure the queues can no longer be woken up, because
* we're sure now mana_poll_tx_cq() can't be running.
*/
--
2.34.1
^ permalink raw reply related
* Re: [PATCH 10/12] fbdev/core: Use fb_is_primary_device() in fb_firmware_edid()
From: Javier Martinez Canillas @ 2023-07-05 8:02 UTC (permalink / raw)
To: Thomas Zimmermann, arnd, deller, daniel, airlied
Cc: linux-hyperv, linux-efi, linux-ia64, linux-sh, linux-fbdev,
dri-devel, linux-mips, sparclinux, linux-riscv, linux-arch,
linux-hexagon, linux-staging, linux-csky, Antonino Daplas,
Maik Broemme, loongarch, linux-arm-kernel, Randy Dunlap,
linux-kernel, Thomas Zimmermann, linux-alpha, linuxppc-dev
In-Reply-To: <20230629121952.10559-11-tzimmermann@suse.de>
Thomas Zimmermann <tzimmermann@suse.de> writes:
> Detect the primary VGA device with fb_is_primary_device() in the
> implementation of fb_firmware_edid(). Remove the existing code.
>
An explanation about why this is possible would be useful here.
> Adapt the function to receive an instance of struct fb_info and
> update all callers.
>
[...]
> -const unsigned char *fb_firmware_edid(struct device *device)
> +const unsigned char *fb_firmware_edid(struct fb_info *info)
> {
> - struct pci_dev *dev = NULL;
> - struct resource *res = NULL;
> unsigned char *edid = NULL;
>
> - if (device)
> - dev = to_pci_dev(device);
> -
> - if (dev)
> - res = &dev->resource[PCI_ROM_RESOURCE];
> -
> - if (res && res->flags & IORESOURCE_ROM_SHADOW)
This open codes what used to be the fb_is_primary_device() logic before
commit 5ca1479cd35d ("fbdev: Simplify fb_is_primary_device for x86").
But now after that commit there is functional change since the ROM
shadowing check would be dropped.
I believe that's OK and Sima explains in their commit message that
vga_default_device() should be enough and the check is redundant.
Still, I think that this change should be documented in your commit
message.
With that change,
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
--
Best regards,
Javier Martinez Canillas
Core Platforms
Red Hat
^ permalink raw reply
* Re: [06/12] arch: Declare screen_info in <asm/screen_info.h>
From: Thomas Zimmermann @ 2023-07-05 8:02 UTC (permalink / raw)
To: Sui Jingfeng, arnd, deller, daniel, airlied
Cc: linux-hyperv, linux-efi, linux-ia64, Anshuman Khandual, linux-sh,
Peter Zijlstra, Catalin Marinas, John Paul Adrian Glaubitz,
linux-fbdev, dri-devel, linux-mips, Max Filippov, Rich Felker,
Guo Ren, Michael Ellerman, H. Peter Anvin, sparclinux,
linux-riscv, Will Deacon, WANG Xuerui, linux-arch,
Kirill A. Shutemov, Yoshinori Sato, linux-hexagon, linux-staging,
Russell King, linux-csky, Ard Biesheuvel, Dave Hansen,
Ingo Molnar, Geert Uytterhoeven, Sami Tolvanen, Juerg Haefliger,
Matt Turner, Huacai Chen, Albert Ou, Kees Cook, Paul E. McKenney,
Chris Zankel, Frederic Weisbecker, Richard Henderson,
Nicholas Piggin, Niklas Schnelle, Russell King (Oracle),
Ivan Kokshaysky, loongarch, Paul Walmsley, Thomas Gleixner,
Zi Yan, linux-arm-kernel, Brian Cain, Thomas Bogendoerfer,
Sebastian Reichel, linux-kernel, Dinh Nguyen, Palmer Dabbelt,
Mike Rapoport (IBM), linux-alpha, Borislav Petkov, Andrew Morton,
Christophe Leroy, linuxppc-dev, David S. Miller, x86
In-Reply-To: <02a6f36c-521f-4ff0-a0bf-1f8781c853e3@loongson.cn>
[-- Attachment #1.1: Type: text/plain, Size: 17182 bytes --]
Hi
Am 05.07.23 um 03:21 schrieb Sui Jingfeng:
> Hi, Thomas
>
>
> I love your patch, yet after applied your patch, the linux kernel fail
> to compile on my LoongArch machine.
screen_info is missing. I think this should be solved with your update
to patch 1.
Best regards
Thomas
>
>
> ```
>
> CC arch/loongarch/kernel/efi.o
> arch/loongarch/kernel/efi.c: In function ‘init_screen_info’:
> arch/loongarch/kernel/efi.c:77:54: error: invalid application of
> ‘sizeof’ to incomplete type ‘struct screen_info’
> 77 | si = early_memremap(screen_info_table, sizeof(*si));
> | ^
> arch/loongarch/kernel/efi.c:82:9: error: ‘screen_info’ undeclared (first
> use in this function)
> 82 | screen_info = *si;
> | ^~~~~~~~~~~
> arch/loongarch/kernel/efi.c:82:9: note: each undeclared identifier is
> reported only once for each function it appears in
> arch/loongarch/kernel/efi.c:82:23: error: invalid use of undefined type
> ‘struct screen_info’
> 82 | screen_info = *si;
> | ^
> arch/loongarch/kernel/efi.c:83:29: error: invalid application of
> ‘sizeof’ to incomplete type ‘struct screen_info’
> 83 | memset(si, 0, sizeof(*si));
> | ^
> arch/loongarch/kernel/efi.c:84:34: error: invalid application of
> ‘sizeof’ to incomplete type ‘struct screen_info’
> 84 | early_memunmap(si, sizeof(*si));
> | ^
> make[3]: *** [scripts/Makefile.build:252: arch/loongarch/kernel/efi.o]
> Error 1
> make[3]: *** Waiting for unfinished jobs....
> make[2]: *** [scripts/Makefile.build:494: arch/loongarch/kernel] Error 2
> make[1]: *** [scripts/Makefile.build:494: arch/loongarch] Error 2
> make[1]: *** Waiting for unfinished jobs....
> make: *** [Makefile:2026: .] Error 2
>
> ```
>
> On 2023/6/29 19:45, Thomas Zimmermann wrote:
>> The variable screen_info does not exist on all architectures. Declare
>> it in <asm-generic/screen_info.h>. All architectures that do declare it
>> will provide it via <asm/screen_info.h>.
>>
>> Add the Kconfig token ARCH_HAS_SCREEN_INFO to guard against access on
>> architectures that don't provide screen_info.
>>
>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
>> Cc: Richard Henderson <richard.henderson@linaro.org>
>> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
>> Cc: Matt Turner <mattst88@gmail.com>
>> Cc: Russell King <linux@armlinux.org.uk>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Will Deacon <will@kernel.org>
>> Cc: Guo Ren <guoren@kernel.org>
>> Cc: Brian Cain <bcain@quicinc.com>
>> Cc: Huacai Chen <chenhuacai@kernel.org>
>> Cc: WANG Xuerui <kernel@xen0n.name>
>> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
>> Cc: Dinh Nguyen <dinguyen@kernel.org>
>> Cc: Michael Ellerman <mpe@ellerman.id.au>
>> Cc: Nicholas Piggin <npiggin@gmail.com>
>> Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
>> Cc: Paul Walmsley <paul.walmsley@sifive.com>
>> Cc: Palmer Dabbelt <palmer@dabbelt.com>
>> Cc: Albert Ou <aou@eecs.berkeley.edu>
>> Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
>> Cc: Rich Felker <dalias@libc.org>
>> Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
>> Cc: "David S. Miller" <davem@davemloft.net>
>> Cc: Thomas Gleixner <tglx@linutronix.de>
>> Cc: Ingo Molnar <mingo@redhat.com>
>> Cc: Borislav Petkov <bp@alien8.de>
>> Cc: Dave Hansen <dave.hansen@linux.intel.com>
>> Cc: x86@kernel.org
>> Cc: "H. Peter Anvin" <hpa@zytor.com>
>> Cc: Chris Zankel <chris@zankel.net>
>> Cc: Max Filippov <jcmvbkbc@gmail.com>
>> Cc: Helge Deller <deller@gmx.de>
>> Cc: Arnd Bergmann <arnd@arndb.de>
>> Cc: Kees Cook <keescook@chromium.org>
>> Cc: "Paul E. McKenney" <paulmck@kernel.org>
>> Cc: Peter Zijlstra <peterz@infradead.org>
>> Cc: Frederic Weisbecker <frederic@kernel.org>
>> Cc: Andrew Morton <akpm@linux-foundation.org>
>> Cc: Ard Biesheuvel <ardb@kernel.org>
>> Cc: Sami Tolvanen <samitolvanen@google.com>
>> Cc: Juerg Haefliger <juerg.haefliger@canonical.com>
>> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
>> Cc: Anshuman Khandual <anshuman.khandual@arm.com>
>> Cc: Niklas Schnelle <schnelle@linux.ibm.com>
>> Cc: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
>> Cc: Linus Walleij <linus.walleij@linaro.org>
>> Cc: Sebastian Reichel <sebastian.reichel@collabora.com>
>> Cc: "Mike Rapoport (IBM)" <rppt@kernel.org>
>> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
>> Cc: Zi Yan <ziy@nvidia.com>
>> Acked-by: WANG Xuerui <git@xen0n.name> # loongarch
>> ---
>> arch/Kconfig | 6 ++++++
>> arch/alpha/Kconfig | 1 +
>> arch/arm/Kconfig | 1 +
>> arch/arm64/Kconfig | 1 +
>> arch/csky/Kconfig | 1 +
>> arch/hexagon/Kconfig | 1 +
>> arch/ia64/Kconfig | 1 +
>> arch/loongarch/Kconfig | 1 +
>> arch/mips/Kconfig | 1 +
>> arch/nios2/Kconfig | 1 +
>> arch/powerpc/Kconfig | 1 +
>> arch/riscv/Kconfig | 1 +
>> arch/sh/Kconfig | 1 +
>> arch/sparc/Kconfig | 1 +
>> arch/x86/Kconfig | 1 +
>> arch/xtensa/Kconfig | 1 +
>> drivers/video/Kconfig | 3 +++
>> include/asm-generic/Kbuild | 1 +
>> include/asm-generic/screen_info.h | 12 ++++++++++++
>> include/linux/screen_info.h | 2 +-
>> 20 files changed, 38 insertions(+), 1 deletion(-)
>> create mode 100644 include/asm-generic/screen_info.h
>>
>> diff --git a/arch/Kconfig b/arch/Kconfig
>> index 205fd23e0cada..2f58293fd7bcb 100644
>> --- a/arch/Kconfig
>> +++ b/arch/Kconfig
>> @@ -1466,6 +1466,12 @@ config ARCH_HAS_NONLEAF_PMD_YOUNG
>> address translations. Page table walkers that clear the
>> accessed bit
>> may use this capability to reduce their search space.
>> +config ARCH_HAS_SCREEN_INFO
>> + bool
>> + help
>> + Selected by architectures that provide a global instance of
>> + screen_info.
>> +
>> source "kernel/gcov/Kconfig"
>> source "scripts/gcc-plugins/Kconfig"
>> diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
>> index a5c2b1aa46b02..d749011d88b14 100644
>> --- a/arch/alpha/Kconfig
>> +++ b/arch/alpha/Kconfig
>> @@ -4,6 +4,7 @@ config ALPHA
>> default y
>> select ARCH_32BIT_USTAT_F_TINODE
>> select ARCH_HAS_CURRENT_STACK_POINTER
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_MIGHT_HAVE_PC_PARPORT
>> select ARCH_MIGHT_HAVE_PC_SERIO
>> select ARCH_NO_PREEMPT
>> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
>> index 0fb4b218f6658..a9d01ee67a90e 100644
>> --- a/arch/arm/Kconfig
>> +++ b/arch/arm/Kconfig
>> @@ -15,6 +15,7 @@ config ARM
>> select ARCH_HAS_MEMBARRIER_SYNC_CORE
>> select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
>> select ARCH_HAS_PTE_SPECIAL if ARM_LPAE
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_HAS_SETUP_DMA_OPS
>> select ARCH_HAS_SET_MEMORY
>> select ARCH_STACKWALK
>> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
>> index 343e1e1cae10a..21addc4715bb3 100644
>> --- a/arch/arm64/Kconfig
>> +++ b/arch/arm64/Kconfig
>> @@ -36,6 +36,7 @@ config ARM64
>> select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
>> select ARCH_HAS_PTE_DEVMAP
>> select ARCH_HAS_PTE_SPECIAL
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_HAS_SETUP_DMA_OPS
>> select ARCH_HAS_SET_DIRECT_MAP
>> select ARCH_HAS_SET_MEMORY
>> diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig
>> index 4df1f8c9d170b..28444e581fc1f 100644
>> --- a/arch/csky/Kconfig
>> +++ b/arch/csky/Kconfig
>> @@ -10,6 +10,7 @@ config CSKY
>> select ARCH_USE_QUEUED_RWLOCKS
>> select ARCH_USE_QUEUED_SPINLOCKS
>> select ARCH_HAS_CURRENT_STACK_POINTER
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_INLINE_READ_LOCK if !PREEMPTION
>> select ARCH_INLINE_READ_LOCK_BH if !PREEMPTION
>> select ARCH_INLINE_READ_LOCK_IRQ if !PREEMPTION
>> diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig
>> index 54eadf2651786..cc683c0a43d34 100644
>> --- a/arch/hexagon/Kconfig
>> +++ b/arch/hexagon/Kconfig
>> @@ -5,6 +5,7 @@ comment "Linux Kernel Configuration for Hexagon"
>> config HEXAGON
>> def_bool y
>> select ARCH_32BIT_OFF_T
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_HAS_SYNC_DMA_FOR_DEVICE
>> select ARCH_NO_PREEMPT
>> select DMA_GLOBAL_POOL
>> diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
>> index e79f15e32a451..8b1e785e6d53d 100644
>> --- a/arch/ia64/Kconfig
>> +++ b/arch/ia64/Kconfig
>> @@ -10,6 +10,7 @@ config IA64
>> bool
>> select ARCH_BINFMT_ELF_EXTRA_PHDRS
>> select ARCH_HAS_DMA_MARK_CLEAN
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_HAS_STRNCPY_FROM_USER
>> select ARCH_HAS_STRNLEN_USER
>> select ARCH_MIGHT_HAVE_PC_PARPORT
>> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
>> index d38b066fc931b..6aab2fb7753da 100644
>> --- a/arch/loongarch/Kconfig
>> +++ b/arch/loongarch/Kconfig
>> @@ -13,6 +13,7 @@ config LOONGARCH
>> select ARCH_HAS_FORTIFY_SOURCE
>> select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS
>> select ARCH_HAS_PTE_SPECIAL
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
>> select ARCH_INLINE_READ_LOCK if !PREEMPTION
>> select ARCH_INLINE_READ_LOCK_BH if !PREEMPTION
>> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
>> index 675a8660cb85a..c0ae09789cb6d 100644
>> --- a/arch/mips/Kconfig
>> +++ b/arch/mips/Kconfig
>> @@ -10,6 +10,7 @@ config MIPS
>> select ARCH_HAS_KCOV
>> select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE if !EVA
>> select ARCH_HAS_PTE_SPECIAL if !(32BIT && CPU_HAS_RIXI)
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_HAS_STRNCPY_FROM_USER
>> select ARCH_HAS_STRNLEN_USER
>> select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
>> diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
>> index e5936417d3cd3..7183eea282212 100644
>> --- a/arch/nios2/Kconfig
>> +++ b/arch/nios2/Kconfig
>> @@ -3,6 +3,7 @@ config NIOS2
>> def_bool y
>> select ARCH_32BIT_OFF_T
>> select ARCH_HAS_DMA_PREP_COHERENT
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_HAS_SYNC_DMA_FOR_CPU
>> select ARCH_HAS_SYNC_DMA_FOR_DEVICE
>> select ARCH_HAS_DMA_SET_UNCACHED
>> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
>> index bff5820b7cda1..b1acad3076180 100644
>> --- a/arch/powerpc/Kconfig
>> +++ b/arch/powerpc/Kconfig
>> @@ -148,6 +148,7 @@ config PPC
>> select ARCH_HAS_PTE_DEVMAP if PPC_BOOK3S_64
>> select ARCH_HAS_PTE_SPECIAL
>> select ARCH_HAS_SCALED_CPUTIME if
>> VIRT_CPU_ACCOUNTING_NATIVE && PPC_BOOK3S_64
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_HAS_SET_MEMORY
>> select ARCH_HAS_STRICT_KERNEL_RWX if (PPC_BOOK3S || PPC_8xx
>> || 40x) && !HIBERNATION
>> select ARCH_HAS_STRICT_KERNEL_RWX if PPC_85xx && !HIBERNATION
>> && !RANDOMIZE_BASE
>> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
>> index 5966ad97c30c3..b5a48f8424af9 100644
>> --- a/arch/riscv/Kconfig
>> +++ b/arch/riscv/Kconfig
>> @@ -29,6 +29,7 @@ config RISCV
>> select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
>> select ARCH_HAS_PMEM_API
>> select ARCH_HAS_PTE_SPECIAL
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_HAS_SET_DIRECT_MAP if MMU
>> select ARCH_HAS_SET_MEMORY if MMU
>> select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL
>> diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
>> index 04b9550cf0070..001f5149952b4 100644
>> --- a/arch/sh/Kconfig
>> +++ b/arch/sh/Kconfig
>> @@ -10,6 +10,7 @@ config SUPERH
>> select ARCH_HAS_GIGANTIC_PAGE
>> select ARCH_HAS_GCOV_PROFILE_ALL
>> select ARCH_HAS_PTE_SPECIAL
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
>> select ARCH_HIBERNATION_POSSIBLE if MMU
>> select ARCH_MIGHT_HAVE_PC_PARPORT
>> diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
>> index 8535e19062f65..e4bfb80b48cfe 100644
>> --- a/arch/sparc/Kconfig
>> +++ b/arch/sparc/Kconfig
>> @@ -13,6 +13,7 @@ config 64BIT
>> config SPARC
>> bool
>> default y
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_MIGHT_HAVE_PC_PARPORT if SPARC64 && PCI
>> select ARCH_MIGHT_HAVE_PC_SERIO
>> select DMA_OPS
>> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>> index 53bab123a8ee4..d7c2bf4ee403d 100644
>> --- a/arch/x86/Kconfig
>> +++ b/arch/x86/Kconfig
>> @@ -91,6 +91,7 @@ config X86
>> select ARCH_HAS_NONLEAF_PMD_YOUNG if PGTABLE_LEVELS > 2
>> select ARCH_HAS_UACCESS_FLUSHCACHE if X86_64
>> select ARCH_HAS_COPY_MC if X86_64
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_HAS_SET_MEMORY
>> select ARCH_HAS_SET_DIRECT_MAP
>> select ARCH_HAS_STRICT_KERNEL_RWX
>> diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
>> index 3c6e5471f025b..c6cbd7459939c 100644
>> --- a/arch/xtensa/Kconfig
>> +++ b/arch/xtensa/Kconfig
>> @@ -8,6 +8,7 @@ config XTENSA
>> select ARCH_HAS_DMA_PREP_COHERENT if MMU
>> select ARCH_HAS_GCOV_PROFILE_ALL
>> select ARCH_HAS_KCOV
>> + select ARCH_HAS_SCREEN_INFO
>> select ARCH_HAS_SYNC_DMA_FOR_CPU if MMU
>> select ARCH_HAS_SYNC_DMA_FOR_DEVICE if MMU
>> select ARCH_HAS_DMA_SET_UNCACHED if MMU
>> diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
>> index 8b2b9ac37c3df..d4a72bea56be0 100644
>> --- a/drivers/video/Kconfig
>> +++ b/drivers/video/Kconfig
>> @@ -21,6 +21,9 @@ config STI_CORE
>> config VIDEO_CMDLINE
>> bool
>> +config ARCH_HAS_SCREEN_INFO
>> + bool
>> +
>> config VIDEO_NOMODESET
>> bool
>> default n
>> diff --git a/include/asm-generic/Kbuild b/include/asm-generic/Kbuild
>> index 941be574bbe00..5e5d4158a4b4b 100644
>> --- a/include/asm-generic/Kbuild
>> +++ b/include/asm-generic/Kbuild
>> @@ -47,6 +47,7 @@ mandatory-y += percpu.h
>> mandatory-y += pgalloc.h
>> mandatory-y += preempt.h
>> mandatory-y += rwonce.h
>> +mandatory-y += screen_info.h
>> mandatory-y += sections.h
>> mandatory-y += serial.h
>> mandatory-y += shmparam.h
>> diff --git a/include/asm-generic/screen_info.h
>> b/include/asm-generic/screen_info.h
>> new file mode 100644
>> index 0000000000000..6fd0e50fabfcd
>> --- /dev/null
>> +++ b/include/asm-generic/screen_info.h
>> @@ -0,0 +1,12 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +
>> +#ifndef _ASM_GENERIC_SCREEN_INFO_H
>> +#define _ASM_GENERIC_SCREEN_INFO_H
>> +
>> +#include <uapi/linux/screen_info.h>
>> +
>> +#if defined(CONFIG_ARCH_HAS_SCREEN_INFO)
>> +extern struct screen_info screen_info;
>> +#endif
>> +
>> +#endif /* _ASM_GENERIC_SCREEN_INFO_H */
>> diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
>> index eab7081392d50..c764b9a51c24b 100644
>> --- a/include/linux/screen_info.h
>> +++ b/include/linux/screen_info.h
>> @@ -4,6 +4,6 @@
>> #include <uapi/linux/screen_info.h>
>> -extern struct screen_info screen_info;
>> +#include <asm/screen_info.h>
>> #endif /* _SCREEN_INFO_H */
>
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
^ permalink raw reply
* Re: [01/12] efi: Do not include <linux/screen_info.h> from EFI header
From: Thomas Zimmermann @ 2023-07-05 8:00 UTC (permalink / raw)
To: Sui Jingfeng, arnd, deller, daniel, airlied
Cc: linux-hyperv, linux-efi, linux-ia64, linux-sh, Catalin Marinas,
linux-fbdev, dri-devel, linux-mips, sparclinux, linux-riscv,
Will Deacon, Ard Biesheuvel, linux-arch, linux-hexagon,
linux-staging, Russell King, linux-csky, loongarch,
linux-arm-kernel, linux-kernel, linux-alpha, linuxppc-dev
In-Reply-To: <26e355dd-049c-fa82-dc5d-565b86339253@loongson.cn>
[-- Attachment #1.1: Type: text/plain, Size: 4609 bytes --]
Hi
Am 05.07.23 um 03:40 schrieb Sui Jingfeng:
> Hi, Thomas
>
>
> I love your patch, LoongArch also have UEFI GOP support,
>
> Maybe the arch/loongarch/kernel/efi.c don't include the '#include
> <linux/screen_info.h>' explicitly.
Oh, thank you for testing. I try to build arch/ changes on all of the
affected platforms, but I cannot build for all of them. I have no means
of building for loongarch ATM.
I'll update the patch according to your feedback.
Best regards
Thomas
>
>
> ```
>
> diff --git a/arch/loongarch/kernel/efi.c b/arch/loongarch/kernel/efi.c
> index 3d448fef3af4..04f4d217aefb 100644
> --- a/arch/loongarch/kernel/efi.c
> +++ b/arch/loongarch/kernel/efi.c
> @@ -19,6 +19,7 @@
> #include <linux/memblock.h>
> #include <linux/reboot.h>
> #include <linux/uaccess.h>
> +#include <linux/screen_info.h>
>
> #include <asm/early_ioremap.h>
> #include <asm/efi.h>
> ```
>
>
> On 2023/6/29 19:45, Thomas Zimmermann wrote:
>> The header file <linux/efi.h> does not need anything from
>> <linux/screen_info.h>. Declare struct screen_info and remove
>> the include statements. Update a number of source files that
>> require struct screen_info's definition.
>>
>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
>> Cc: Ard Biesheuvel <ardb@kernel.org>
>> Cc: Russell King <linux@armlinux.org.uk>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Will Deacon <will@kernel.org>
>> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
>
> With the above issue solved, please take my R-B if you would like.
>
>
> Reviewed-by: Sui Jingfeng <suijingfeng@loongson.cn>
>
>> ---
>> arch/arm/kernel/efi.c | 2 ++
>> arch/arm64/kernel/efi.c | 1 +
>> drivers/firmware/efi/libstub/efi-stub-entry.c | 2 ++
>> drivers/firmware/efi/libstub/screen_info.c | 2 ++
>> include/linux/efi.h | 3 ++-
>> 5 files changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/arm/kernel/efi.c b/arch/arm/kernel/efi.c
>> index e2b9d2618c672..e94655ef16bb3 100644
>> --- a/arch/arm/kernel/efi.c
>> +++ b/arch/arm/kernel/efi.c
>> @@ -5,6 +5,8 @@
>> #include <linux/efi.h>
>> #include <linux/memblock.h>
>> +#include <linux/screen_info.h>
>> +
>> #include <asm/efi.h>
>> #include <asm/mach/map.h>
>> #include <asm/mmu_context.h>
>> diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
>> index baab8dd3ead3c..3afbe503b066f 100644
>> --- a/arch/arm64/kernel/efi.c
>> +++ b/arch/arm64/kernel/efi.c
>> @@ -9,6 +9,7 @@
>> #include <linux/efi.h>
>> #include <linux/init.h>
>> +#include <linux/screen_info.h>
>> #include <asm/efi.h>
>> #include <asm/stacktrace.h>
>> diff --git a/drivers/firmware/efi/libstub/efi-stub-entry.c
>> b/drivers/firmware/efi/libstub/efi-stub-entry.c
>> index cc4dcaea67fa6..2f1902e5d4075 100644
>> --- a/drivers/firmware/efi/libstub/efi-stub-entry.c
>> +++ b/drivers/firmware/efi/libstub/efi-stub-entry.c
>> @@ -1,6 +1,8 @@
>> // SPDX-License-Identifier: GPL-2.0-only
>> #include <linux/efi.h>
>> +#include <linux/screen_info.h>
>> +
>> #include <asm/efi.h>
>> #include "efistub.h"
>> diff --git a/drivers/firmware/efi/libstub/screen_info.c
>> b/drivers/firmware/efi/libstub/screen_info.c
>> index 4be1c4d1f922b..a51ec201ca3cb 100644
>> --- a/drivers/firmware/efi/libstub/screen_info.c
>> +++ b/drivers/firmware/efi/libstub/screen_info.c
>> @@ -1,6 +1,8 @@
>> // SPDX-License-Identifier: GPL-2.0
>> #include <linux/efi.h>
>> +#include <linux/screen_info.h>
>> +
>> #include <asm/efi.h>
>> #include "efistub.h"
>> diff --git a/include/linux/efi.h b/include/linux/efi.h
>> index 571d1a6e1b744..360895a5572c0 100644
>> --- a/include/linux/efi.h
>> +++ b/include/linux/efi.h
>> @@ -24,10 +24,11 @@
>> #include <linux/range.h>
>> #include <linux/reboot.h>
>> #include <linux/uuid.h>
>> -#include <linux/screen_info.h>
>> #include <asm/page.h>
>> +struct screen_info;
>> +
>> #define EFI_SUCCESS 0
>> #define EFI_LOAD_ERROR ( 1 | (1UL << (BITS_PER_LONG-1)))
>> #define EFI_INVALID_PARAMETER ( 2 | (1UL << (BITS_PER_LONG-1)))
>
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
^ permalink raw reply
* Re: [PATCH 08/12] drivers/firmware: Remove trailing whitespaces
From: Javier Martinez Canillas @ 2023-07-05 7:46 UTC (permalink / raw)
To: Thomas Zimmermann, arnd, deller, daniel, airlied
Cc: linux-arch, linux-hyperv, linux-efi, linux-ia64,
Thomas Zimmermann, linux-sh, linux-hexagon, linux-staging,
linux-kernel, linux-csky, linux-mips, linux-fbdev, dri-devel,
loongarch, linux-alpha, sparclinux, linux-riscv, linuxppc-dev,
linux-arm-kernel
In-Reply-To: <20230629121952.10559-9-tzimmermann@suse.de>
Thomas Zimmermann <tzimmermann@suse.de> writes:
> Fix coding style. No functional changes.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
--
Best regards,
Javier Martinez Canillas
Core Platforms
Red Hat
^ permalink raw reply
* Re: [11/12] fbdev/core: Protect edid_info with CONFIG_ARCH_HAS_EDID_INFO
From: Sui Jingfeng @ 2023-07-05 1:43 UTC (permalink / raw)
To: Thomas Zimmermann, arnd, deller, daniel, airlied
Cc: linux-arch, linux-hyperv, linux-efi, linux-ia64, linux-sh,
linux-hexagon, linux-staging, linux-kernel, linux-csky,
linux-mips, linux-fbdev, Randy Dunlap, dri-devel, loongarch,
linux-alpha, sparclinux, linux-riscv, linuxppc-dev,
linux-arm-kernel
In-Reply-To: <20230629121952.10559-12-tzimmermann@suse.de>
Hi,
On 2023/6/29 19:45, Thomas Zimmermann wrote:
> Guard usage of edid_info with CONFIG_ARCH_HAS_EDID_INFO instead
> of CONFIG_X86. No functional changes.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Sui Jingfeng <suijingfeng@loongson.cn>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Cc: Helge Deller <deller@gmx.de>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> ---
> drivers/video/fbdev/core/fbmon.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/video/fbdev/core/fbmon.c b/drivers/video/fbdev/core/fbmon.c
> index 35be4431f649a..9ae063021e431 100644
> --- a/drivers/video/fbdev/core/fbmon.c
> +++ b/drivers/video/fbdev/core/fbmon.c
> @@ -1480,17 +1480,19 @@ int fb_validate_mode(const struct fb_var_screeninfo *var, struct fb_info *info)
> -EINVAL : 0;
> }
>
> -#if defined(CONFIG_FIRMWARE_EDID) && defined(CONFIG_X86)
> +#if defined(CONFIG_FIRMWARE_EDID)
> const unsigned char *fb_firmware_edid(struct fb_info *info)
> {
> unsigned char *edid = NULL;
>
> +#if defined(CONFIG_ARCH_HAS_EDID_INFO)
> /*
> * We need to ensure that the EDID block is only
> * returned for the primary graphics adapter.
> */
> if (fb_is_primary_device(info))
> edid = edid_info.dummy;
> +#endif
>
> return edid;
> }
^ permalink raw reply
* Re: [03/12] sysfb: Do not include <linux/screen_info.h> from sysfb header
From: Sui Jingfeng @ 2023-07-05 1:41 UTC (permalink / raw)
To: Thomas Zimmermann, arnd, deller, daniel, airlied
Cc: linux-hyperv, linux-efi, linux-ia64, linux-sh, linux-fbdev,
dri-devel, linux-mips, sparclinux, linux-riscv, Ard Biesheuvel,
linux-arch, linux-hexagon, linux-staging,
Javier Martinez Canillas, linux-csky, Hans de Goede, loongarch,
linux-arm-kernel, linux-kernel, linux-alpha, linuxppc-dev
In-Reply-To: <20230629121952.10559-4-tzimmermann@suse.de>
On 2023/6/29 19:45, Thomas Zimmermann wrote:
> The header file <linux/sysfb.h> does not need anything from
> <linux/screen_info.h>. Declare struct screen_info and remove
> the include statements.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Hans de Goede <hdegoede@redhat.com>
> Cc: Javier Martinez Canillas <javierm@redhat.com>
> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Sui Jingfeng <suijingfeng@loongson.cn>
> ---
> include/linux/sysfb.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/sysfb.h b/include/linux/sysfb.h
> index c1ef5fc60a3cb..19cb803dd5ecd 100644
> --- a/include/linux/sysfb.h
> +++ b/include/linux/sysfb.h
> @@ -9,7 +9,8 @@
>
> #include <linux/kernel.h>
> #include <linux/platform_data/simplefb.h>
> -#include <linux/screen_info.h>
> +
> +struct screen_info;
>
> enum {
> M_I17, /* 17-Inch iMac */
^ permalink raw reply
* Re: [01/12] efi: Do not include <linux/screen_info.h> from EFI header
From: Sui Jingfeng @ 2023-07-05 1:40 UTC (permalink / raw)
To: Thomas Zimmermann, arnd, deller, daniel, airlied
Cc: linux-hyperv, linux-efi, linux-ia64, linux-sh, Catalin Marinas,
linux-fbdev, dri-devel, linux-mips, sparclinux, linux-riscv,
Will Deacon, Ard Biesheuvel, linux-arch, linux-hexagon,
linux-staging, Russell King, linux-csky, loongarch,
linux-arm-kernel, linux-kernel, linux-alpha, linuxppc-dev
In-Reply-To: <20230629121952.10559-2-tzimmermann@suse.de>
Hi, Thomas
I love your patch, LoongArch also have UEFI GOP support,
Maybe the arch/loongarch/kernel/efi.c don't include the '#include
<linux/screen_info.h>' explicitly.
```
diff --git a/arch/loongarch/kernel/efi.c b/arch/loongarch/kernel/efi.c
index 3d448fef3af4..04f4d217aefb 100644
--- a/arch/loongarch/kernel/efi.c
+++ b/arch/loongarch/kernel/efi.c
@@ -19,6 +19,7 @@
#include <linux/memblock.h>
#include <linux/reboot.h>
#include <linux/uaccess.h>
+#include <linux/screen_info.h>
#include <asm/early_ioremap.h>
#include <asm/efi.h>
```
On 2023/6/29 19:45, Thomas Zimmermann wrote:
> The header file <linux/efi.h> does not need anything from
> <linux/screen_info.h>. Declare struct screen_info and remove
> the include statements. Update a number of source files that
> require struct screen_info's definition.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
With the above issue solved, please take my R-B if you would like.
Reviewed-by: Sui Jingfeng <suijingfeng@loongson.cn>
> ---
> arch/arm/kernel/efi.c | 2 ++
> arch/arm64/kernel/efi.c | 1 +
> drivers/firmware/efi/libstub/efi-stub-entry.c | 2 ++
> drivers/firmware/efi/libstub/screen_info.c | 2 ++
> include/linux/efi.h | 3 ++-
> 5 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/kernel/efi.c b/arch/arm/kernel/efi.c
> index e2b9d2618c672..e94655ef16bb3 100644
> --- a/arch/arm/kernel/efi.c
> +++ b/arch/arm/kernel/efi.c
> @@ -5,6 +5,8 @@
>
> #include <linux/efi.h>
> #include <linux/memblock.h>
> +#include <linux/screen_info.h>
> +
> #include <asm/efi.h>
> #include <asm/mach/map.h>
> #include <asm/mmu_context.h>
> diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
> index baab8dd3ead3c..3afbe503b066f 100644
> --- a/arch/arm64/kernel/efi.c
> +++ b/arch/arm64/kernel/efi.c
> @@ -9,6 +9,7 @@
>
> #include <linux/efi.h>
> #include <linux/init.h>
> +#include <linux/screen_info.h>
>
> #include <asm/efi.h>
> #include <asm/stacktrace.h>
> diff --git a/drivers/firmware/efi/libstub/efi-stub-entry.c b/drivers/firmware/efi/libstub/efi-stub-entry.c
> index cc4dcaea67fa6..2f1902e5d4075 100644
> --- a/drivers/firmware/efi/libstub/efi-stub-entry.c
> +++ b/drivers/firmware/efi/libstub/efi-stub-entry.c
> @@ -1,6 +1,8 @@
> // SPDX-License-Identifier: GPL-2.0-only
>
> #include <linux/efi.h>
> +#include <linux/screen_info.h>
> +
> #include <asm/efi.h>
>
> #include "efistub.h"
> diff --git a/drivers/firmware/efi/libstub/screen_info.c b/drivers/firmware/efi/libstub/screen_info.c
> index 4be1c4d1f922b..a51ec201ca3cb 100644
> --- a/drivers/firmware/efi/libstub/screen_info.c
> +++ b/drivers/firmware/efi/libstub/screen_info.c
> @@ -1,6 +1,8 @@
> // SPDX-License-Identifier: GPL-2.0
>
> #include <linux/efi.h>
> +#include <linux/screen_info.h>
> +
> #include <asm/efi.h>
>
> #include "efistub.h"
> diff --git a/include/linux/efi.h b/include/linux/efi.h
> index 571d1a6e1b744..360895a5572c0 100644
> --- a/include/linux/efi.h
> +++ b/include/linux/efi.h
> @@ -24,10 +24,11 @@
> #include <linux/range.h>
> #include <linux/reboot.h>
> #include <linux/uuid.h>
> -#include <linux/screen_info.h>
>
> #include <asm/page.h>
>
> +struct screen_info;
> +
> #define EFI_SUCCESS 0
> #define EFI_LOAD_ERROR ( 1 | (1UL << (BITS_PER_LONG-1)))
> #define EFI_INVALID_PARAMETER ( 2 | (1UL << (BITS_PER_LONG-1)))
^ permalink raw reply related
* Re: [08/12] drivers/firmware: Remove trailing whitespaces
From: Sui Jingfeng @ 2023-07-05 1:26 UTC (permalink / raw)
To: Thomas Zimmermann, arnd, deller, daniel, airlied
Cc: linux-arch, linux-hyperv, linux-efi, linux-ia64, linux-sh,
linux-hexagon, linux-staging, linux-kernel, linux-csky,
linux-mips, linux-fbdev, dri-devel, loongarch, linux-alpha,
sparclinux, linux-riscv, linuxppc-dev, linux-arm-kernel
In-Reply-To: <20230629121952.10559-9-tzimmermann@suse.de>
Hi,
On 2023/6/29 19:45, Thomas Zimmermann wrote:
> Fix coding style. No functional changes.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Sui Jingfeng <suijingfeng@loongson.cn>
> ---
> drivers/firmware/Kconfig | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
> index b59e3041fd627..0432737bbb8b4 100644
> --- a/drivers/firmware/Kconfig
> +++ b/drivers/firmware/Kconfig
> @@ -99,7 +99,7 @@ config EFI_PCDP
> You must also enable the appropriate drivers (serial, VGA, etc.)
>
> See DIG64_HCDPv20_042804.pdf available from
> - <http://www.dig64.org/specifications/>
> + <http://www.dig64.org/specifications/>
>
> config DMIID
> bool "Export DMI identification via sysfs to userspace"
^ permalink raw reply
* Re: [05/12] arch: Remove trailing whitespaces
From: Sui Jingfeng @ 2023-07-05 1:25 UTC (permalink / raw)
To: Thomas Zimmermann, arnd, deller, daniel, airlied
Cc: linux-hyperv, linux-efi, linux-ia64, linux-sh, Peter Zijlstra,
linux-fbdev, dri-devel, linux-mips, Rich Felker, sparclinux,
linux-riscv, linux-arch, Yoshinori Sato, linux-hexagon,
linux-staging, linux-csky, Geert Uytterhoeven, Zi Yan,
Anshuman Khandual, Niklas Schnelle, loongarch,
John Paul Adrian Glaubitz, linux-arm-kernel, Arnd Bergmann,
linux-kernel, Mike Rapoport (IBM), linux-alpha, Andrew Morton,
linuxppc-dev, Kirill A. Shutemov
In-Reply-To: <20230629121952.10559-6-tzimmermann@suse.de>
On 2023/6/29 19:45, Thomas Zimmermann wrote:
> Fix coding style. No functional changes.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
> Cc: Rich Felker <dalias@libc.org>
> Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Arnd Bergmann <arnd@kernel.org>
> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> Cc: Anshuman Khandual <anshuman.khandual@arm.com>
> Cc: Niklas Schnelle <schnelle@linux.ibm.com>
> Cc: Zi Yan <ziy@nvidia.com>
> Cc: "Mike Rapoport (IBM)" <rppt@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Sui Jingfeng <suijingfeng@loongson.cn>
> ---
> arch/ia64/Kconfig | 4 ++--
> arch/sh/Kconfig | 6 +++---
> 2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
> index 21fa63ce5ffc0..e79f15e32a451 100644
> --- a/arch/ia64/Kconfig
> +++ b/arch/ia64/Kconfig
> @@ -260,7 +260,7 @@ config PERMIT_BSP_REMOVE
> default n
> help
> Say Y here if your platform SAL will support removal of BSP with HOTPLUG_CPU
> - support.
> + support.
>
> config FORCE_CPEI_RETARGET
> bool "Force assumption that CPEI can be re-targeted"
> @@ -335,7 +335,7 @@ config IA64_PALINFO
> config IA64_MC_ERR_INJECT
> tristate "MC error injection support"
> help
> - Adds support for MC error injection. If enabled, the kernel
> + Adds support for MC error injection. If enabled, the kernel
> will provide a sysfs interface for user applications to
> call MC error injection PAL procedures to inject various errors.
> This is a useful tool for MCA testing.
> diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
> index 9652d367fc377..04b9550cf0070 100644
> --- a/arch/sh/Kconfig
> +++ b/arch/sh/Kconfig
> @@ -234,7 +234,7 @@ config CPU_SUBTYPE_SH7201
> select CPU_SH2A
> select CPU_HAS_FPU
> select SYS_SUPPORTS_SH_MTU2
> -
> +
> config CPU_SUBTYPE_SH7203
> bool "Support SH7203 processor"
> select CPU_SH2A
> @@ -496,7 +496,7 @@ config CPU_SUBTYPE_SH7366
> endchoice
>
> source "arch/sh/mm/Kconfig"
> -
> +
> source "arch/sh/Kconfig.cpu"
>
> source "arch/sh/boards/Kconfig"
> @@ -647,7 +647,7 @@ config GUSA
> This is the default implementation for both UP and non-ll/sc
> CPUs, and is used by the libc, amongst others.
>
> - For additional information, design information can be found
> + For additional information, design information can be found
> in <http://lc.linux.or.jp/lc2002/papers/niibe0919p.pdf>.
>
> This should only be disabled for special cases where alternate
^ permalink raw reply
* Re: [06/12] arch: Declare screen_info in <asm/screen_info.h>
From: Sui Jingfeng @ 2023-07-05 1:21 UTC (permalink / raw)
To: Thomas Zimmermann, arnd, deller, daniel, airlied
Cc: linux-hyperv, linux-efi, linux-ia64, Anshuman Khandual, linux-sh,
Peter Zijlstra, Catalin Marinas, John Paul Adrian Glaubitz,
linux-fbdev, dri-devel, linux-mips, Max Filippov, Rich Felker,
Guo Ren, Michael Ellerman, H. Peter Anvin, sparclinux,
linux-riscv, Will Deacon, WANG Xuerui, linux-arch,
Kirill A. Shutemov, Yoshinori Sato, linux-hexagon, linux-staging,
Russell King, linux-csky, Ard Biesheuvel, Dave Hansen,
Ingo Molnar, Geert Uytterhoeven, Sami Tolvanen, Juerg Haefliger,
Matt Turner, Huacai Chen, Albert Ou, Kees Cook, Paul E. McKenney,
Chris Zankel, Frederic Weisbecker, Richard Henderson,
Nicholas Piggin, Niklas Schnelle, Russell King (Oracle),
Ivan Kokshaysky, loongarch, Paul Walmsley, Thomas Gleixner,
Zi Yan, linux-arm-kernel, Brian Cain, Thomas Bogendoerfer,
Sebastian Reichel, linux-kernel, Dinh Nguyen, Palmer Dabbelt,
Mike Rapoport (IBM), linux-alpha, Borislav Petkov, Andrew Morton,
Christophe Leroy, linuxppc-dev, David S. Miller, x86
In-Reply-To: <20230629121952.10559-7-tzimmermann@suse.de>
Hi, Thomas
I love your patch, yet after applied your patch, the linux kernel fail
to compile on my LoongArch machine.
```
CC arch/loongarch/kernel/efi.o
arch/loongarch/kernel/efi.c: In function ‘init_screen_info’:
arch/loongarch/kernel/efi.c:77:54: error: invalid application of
‘sizeof’ to incomplete type ‘struct screen_info’
77 | si = early_memremap(screen_info_table, sizeof(*si));
| ^
arch/loongarch/kernel/efi.c:82:9: error: ‘screen_info’ undeclared (first
use in this function)
82 | screen_info = *si;
| ^~~~~~~~~~~
arch/loongarch/kernel/efi.c:82:9: note: each undeclared identifier is
reported only once for each function it appears in
arch/loongarch/kernel/efi.c:82:23: error: invalid use of undefined type
‘struct screen_info’
82 | screen_info = *si;
| ^
arch/loongarch/kernel/efi.c:83:29: error: invalid application of
‘sizeof’ to incomplete type ‘struct screen_info’
83 | memset(si, 0, sizeof(*si));
| ^
arch/loongarch/kernel/efi.c:84:34: error: invalid application of
‘sizeof’ to incomplete type ‘struct screen_info’
84 | early_memunmap(si, sizeof(*si));
| ^
make[3]: *** [scripts/Makefile.build:252: arch/loongarch/kernel/efi.o]
Error 1
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [scripts/Makefile.build:494: arch/loongarch/kernel] Error 2
make[1]: *** [scripts/Makefile.build:494: arch/loongarch] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:2026: .] Error 2
```
On 2023/6/29 19:45, Thomas Zimmermann wrote:
> The variable screen_info does not exist on all architectures. Declare
> it in <asm-generic/screen_info.h>. All architectures that do declare it
> will provide it via <asm/screen_info.h>.
>
> Add the Kconfig token ARCH_HAS_SCREEN_INFO to guard against access on
> architectures that don't provide screen_info.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Richard Henderson <richard.henderson@linaro.org>
> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: Russell King <linux@armlinux.org.uk>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Guo Ren <guoren@kernel.org>
> Cc: Brian Cain <bcain@quicinc.com>
> Cc: Huacai Chen <chenhuacai@kernel.org>
> Cc: WANG Xuerui <kernel@xen0n.name>
> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
> Cc: Dinh Nguyen <dinguyen@kernel.org>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Nicholas Piggin <npiggin@gmail.com>
> Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
> Cc: Paul Walmsley <paul.walmsley@sifive.com>
> Cc: Palmer Dabbelt <palmer@dabbelt.com>
> Cc: Albert Ou <aou@eecs.berkeley.edu>
> Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
> Cc: Rich Felker <dalias@libc.org>
> Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: x86@kernel.org
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: Chris Zankel <chris@zankel.net>
> Cc: Max Filippov <jcmvbkbc@gmail.com>
> Cc: Helge Deller <deller@gmx.de>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: "Paul E. McKenney" <paulmck@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Frederic Weisbecker <frederic@kernel.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Sami Tolvanen <samitolvanen@google.com>
> Cc: Juerg Haefliger <juerg.haefliger@canonical.com>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Anshuman Khandual <anshuman.khandual@arm.com>
> Cc: Niklas Schnelle <schnelle@linux.ibm.com>
> Cc: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Sebastian Reichel <sebastian.reichel@collabora.com>
> Cc: "Mike Rapoport (IBM)" <rppt@kernel.org>
> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> Cc: Zi Yan <ziy@nvidia.com>
> Acked-by: WANG Xuerui <git@xen0n.name> # loongarch
> ---
> arch/Kconfig | 6 ++++++
> arch/alpha/Kconfig | 1 +
> arch/arm/Kconfig | 1 +
> arch/arm64/Kconfig | 1 +
> arch/csky/Kconfig | 1 +
> arch/hexagon/Kconfig | 1 +
> arch/ia64/Kconfig | 1 +
> arch/loongarch/Kconfig | 1 +
> arch/mips/Kconfig | 1 +
> arch/nios2/Kconfig | 1 +
> arch/powerpc/Kconfig | 1 +
> arch/riscv/Kconfig | 1 +
> arch/sh/Kconfig | 1 +
> arch/sparc/Kconfig | 1 +
> arch/x86/Kconfig | 1 +
> arch/xtensa/Kconfig | 1 +
> drivers/video/Kconfig | 3 +++
> include/asm-generic/Kbuild | 1 +
> include/asm-generic/screen_info.h | 12 ++++++++++++
> include/linux/screen_info.h | 2 +-
> 20 files changed, 38 insertions(+), 1 deletion(-)
> create mode 100644 include/asm-generic/screen_info.h
>
> diff --git a/arch/Kconfig b/arch/Kconfig
> index 205fd23e0cada..2f58293fd7bcb 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -1466,6 +1466,12 @@ config ARCH_HAS_NONLEAF_PMD_YOUNG
> address translations. Page table walkers that clear the accessed bit
> may use this capability to reduce their search space.
>
> +config ARCH_HAS_SCREEN_INFO
> + bool
> + help
> + Selected by architectures that provide a global instance of
> + screen_info.
> +
> source "kernel/gcov/Kconfig"
>
> source "scripts/gcc-plugins/Kconfig"
> diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
> index a5c2b1aa46b02..d749011d88b14 100644
> --- a/arch/alpha/Kconfig
> +++ b/arch/alpha/Kconfig
> @@ -4,6 +4,7 @@ config ALPHA
> default y
> select ARCH_32BIT_USTAT_F_TINODE
> select ARCH_HAS_CURRENT_STACK_POINTER
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_MIGHT_HAVE_PC_PARPORT
> select ARCH_MIGHT_HAVE_PC_SERIO
> select ARCH_NO_PREEMPT
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index 0fb4b218f6658..a9d01ee67a90e 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -15,6 +15,7 @@ config ARM
> select ARCH_HAS_MEMBARRIER_SYNC_CORE
> select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
> select ARCH_HAS_PTE_SPECIAL if ARM_LPAE
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_HAS_SETUP_DMA_OPS
> select ARCH_HAS_SET_MEMORY
> select ARCH_STACKWALK
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 343e1e1cae10a..21addc4715bb3 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -36,6 +36,7 @@ config ARM64
> select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
> select ARCH_HAS_PTE_DEVMAP
> select ARCH_HAS_PTE_SPECIAL
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_HAS_SETUP_DMA_OPS
> select ARCH_HAS_SET_DIRECT_MAP
> select ARCH_HAS_SET_MEMORY
> diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig
> index 4df1f8c9d170b..28444e581fc1f 100644
> --- a/arch/csky/Kconfig
> +++ b/arch/csky/Kconfig
> @@ -10,6 +10,7 @@ config CSKY
> select ARCH_USE_QUEUED_RWLOCKS
> select ARCH_USE_QUEUED_SPINLOCKS
> select ARCH_HAS_CURRENT_STACK_POINTER
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_INLINE_READ_LOCK if !PREEMPTION
> select ARCH_INLINE_READ_LOCK_BH if !PREEMPTION
> select ARCH_INLINE_READ_LOCK_IRQ if !PREEMPTION
> diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig
> index 54eadf2651786..cc683c0a43d34 100644
> --- a/arch/hexagon/Kconfig
> +++ b/arch/hexagon/Kconfig
> @@ -5,6 +5,7 @@ comment "Linux Kernel Configuration for Hexagon"
> config HEXAGON
> def_bool y
> select ARCH_32BIT_OFF_T
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_HAS_SYNC_DMA_FOR_DEVICE
> select ARCH_NO_PREEMPT
> select DMA_GLOBAL_POOL
> diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
> index e79f15e32a451..8b1e785e6d53d 100644
> --- a/arch/ia64/Kconfig
> +++ b/arch/ia64/Kconfig
> @@ -10,6 +10,7 @@ config IA64
> bool
> select ARCH_BINFMT_ELF_EXTRA_PHDRS
> select ARCH_HAS_DMA_MARK_CLEAN
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_HAS_STRNCPY_FROM_USER
> select ARCH_HAS_STRNLEN_USER
> select ARCH_MIGHT_HAVE_PC_PARPORT
> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
> index d38b066fc931b..6aab2fb7753da 100644
> --- a/arch/loongarch/Kconfig
> +++ b/arch/loongarch/Kconfig
> @@ -13,6 +13,7 @@ config LOONGARCH
> select ARCH_HAS_FORTIFY_SOURCE
> select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS
> select ARCH_HAS_PTE_SPECIAL
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
> select ARCH_INLINE_READ_LOCK if !PREEMPTION
> select ARCH_INLINE_READ_LOCK_BH if !PREEMPTION
> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> index 675a8660cb85a..c0ae09789cb6d 100644
> --- a/arch/mips/Kconfig
> +++ b/arch/mips/Kconfig
> @@ -10,6 +10,7 @@ config MIPS
> select ARCH_HAS_KCOV
> select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE if !EVA
> select ARCH_HAS_PTE_SPECIAL if !(32BIT && CPU_HAS_RIXI)
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_HAS_STRNCPY_FROM_USER
> select ARCH_HAS_STRNLEN_USER
> select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
> diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
> index e5936417d3cd3..7183eea282212 100644
> --- a/arch/nios2/Kconfig
> +++ b/arch/nios2/Kconfig
> @@ -3,6 +3,7 @@ config NIOS2
> def_bool y
> select ARCH_32BIT_OFF_T
> select ARCH_HAS_DMA_PREP_COHERENT
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_HAS_SYNC_DMA_FOR_CPU
> select ARCH_HAS_SYNC_DMA_FOR_DEVICE
> select ARCH_HAS_DMA_SET_UNCACHED
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index bff5820b7cda1..b1acad3076180 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -148,6 +148,7 @@ config PPC
> select ARCH_HAS_PTE_DEVMAP if PPC_BOOK3S_64
> select ARCH_HAS_PTE_SPECIAL
> select ARCH_HAS_SCALED_CPUTIME if VIRT_CPU_ACCOUNTING_NATIVE && PPC_BOOK3S_64
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_HAS_SET_MEMORY
> select ARCH_HAS_STRICT_KERNEL_RWX if (PPC_BOOK3S || PPC_8xx || 40x) && !HIBERNATION
> select ARCH_HAS_STRICT_KERNEL_RWX if PPC_85xx && !HIBERNATION && !RANDOMIZE_BASE
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index 5966ad97c30c3..b5a48f8424af9 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -29,6 +29,7 @@ config RISCV
> select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
> select ARCH_HAS_PMEM_API
> select ARCH_HAS_PTE_SPECIAL
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_HAS_SET_DIRECT_MAP if MMU
> select ARCH_HAS_SET_MEMORY if MMU
> select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL
> diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
> index 04b9550cf0070..001f5149952b4 100644
> --- a/arch/sh/Kconfig
> +++ b/arch/sh/Kconfig
> @@ -10,6 +10,7 @@ config SUPERH
> select ARCH_HAS_GIGANTIC_PAGE
> select ARCH_HAS_GCOV_PROFILE_ALL
> select ARCH_HAS_PTE_SPECIAL
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
> select ARCH_HIBERNATION_POSSIBLE if MMU
> select ARCH_MIGHT_HAVE_PC_PARPORT
> diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
> index 8535e19062f65..e4bfb80b48cfe 100644
> --- a/arch/sparc/Kconfig
> +++ b/arch/sparc/Kconfig
> @@ -13,6 +13,7 @@ config 64BIT
> config SPARC
> bool
> default y
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_MIGHT_HAVE_PC_PARPORT if SPARC64 && PCI
> select ARCH_MIGHT_HAVE_PC_SERIO
> select DMA_OPS
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 53bab123a8ee4..d7c2bf4ee403d 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -91,6 +91,7 @@ config X86
> select ARCH_HAS_NONLEAF_PMD_YOUNG if PGTABLE_LEVELS > 2
> select ARCH_HAS_UACCESS_FLUSHCACHE if X86_64
> select ARCH_HAS_COPY_MC if X86_64
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_HAS_SET_MEMORY
> select ARCH_HAS_SET_DIRECT_MAP
> select ARCH_HAS_STRICT_KERNEL_RWX
> diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
> index 3c6e5471f025b..c6cbd7459939c 100644
> --- a/arch/xtensa/Kconfig
> +++ b/arch/xtensa/Kconfig
> @@ -8,6 +8,7 @@ config XTENSA
> select ARCH_HAS_DMA_PREP_COHERENT if MMU
> select ARCH_HAS_GCOV_PROFILE_ALL
> select ARCH_HAS_KCOV
> + select ARCH_HAS_SCREEN_INFO
> select ARCH_HAS_SYNC_DMA_FOR_CPU if MMU
> select ARCH_HAS_SYNC_DMA_FOR_DEVICE if MMU
> select ARCH_HAS_DMA_SET_UNCACHED if MMU
> diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
> index 8b2b9ac37c3df..d4a72bea56be0 100644
> --- a/drivers/video/Kconfig
> +++ b/drivers/video/Kconfig
> @@ -21,6 +21,9 @@ config STI_CORE
> config VIDEO_CMDLINE
> bool
>
> +config ARCH_HAS_SCREEN_INFO
> + bool
> +
> config VIDEO_NOMODESET
> bool
> default n
> diff --git a/include/asm-generic/Kbuild b/include/asm-generic/Kbuild
> index 941be574bbe00..5e5d4158a4b4b 100644
> --- a/include/asm-generic/Kbuild
> +++ b/include/asm-generic/Kbuild
> @@ -47,6 +47,7 @@ mandatory-y += percpu.h
> mandatory-y += pgalloc.h
> mandatory-y += preempt.h
> mandatory-y += rwonce.h
> +mandatory-y += screen_info.h
> mandatory-y += sections.h
> mandatory-y += serial.h
> mandatory-y += shmparam.h
> diff --git a/include/asm-generic/screen_info.h b/include/asm-generic/screen_info.h
> new file mode 100644
> index 0000000000000..6fd0e50fabfcd
> --- /dev/null
> +++ b/include/asm-generic/screen_info.h
> @@ -0,0 +1,12 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifndef _ASM_GENERIC_SCREEN_INFO_H
> +#define _ASM_GENERIC_SCREEN_INFO_H
> +
> +#include <uapi/linux/screen_info.h>
> +
> +#if defined(CONFIG_ARCH_HAS_SCREEN_INFO)
> +extern struct screen_info screen_info;
> +#endif
> +
> +#endif /* _ASM_GENERIC_SCREEN_INFO_H */
> diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
> index eab7081392d50..c764b9a51c24b 100644
> --- a/include/linux/screen_info.h
> +++ b/include/linux/screen_info.h
> @@ -4,6 +4,6 @@
>
> #include <uapi/linux/screen_info.h>
>
> -extern struct screen_info screen_info;
> +#include <asm/screen_info.h>
>
> #endif /* _SCREEN_INFO_H */
^ permalink raw reply
* Hyper-V vsock streams do not fill the supplied buffer in full
From: Gary Guo @ 2023-07-04 22:45 UTC (permalink / raw)
To: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
Stefano Garzarella
Cc: linux-hyperv, virtualization, netdev, linux-kernel
When a vsock stream is called with recvmsg with a buffer, it only fills
the buffer with data from the first single VM packet. Even if there are
more VM packets at the time and the buffer is still not completely
filled, it will just leave the buffer partially filled.
This causes some issues when in WSLD which uses the vsock in
non-blocking mode and uses epoll.
For stream-oriented sockets, the epoll man page [1] says that
> For stream-oriented files (e.g., pipe, FIFO, stream socket),
> the condition that the read/write I/O space is exhausted can
> also be detected by checking the amount of data read from /
> written to the target file descriptor. For example, if you
> call read(2) by asking to read a certain amount of data and
> read(2) returns a lower number of bytes, you can be sure of
> having exhausted the read I/O space for the file descriptor.
This has been used as an optimisation in the wild for reducing number
of syscalls required for stream sockets (by asserting that the socket
will not have to polled to EAGAIN in edge-trigger mode, if the buffer
given to recvmsg is not filled completely). An example is Tokio, which
starting in v1.21.0 [2].
When this optimisation combines with the behaviour of Hyper-V vsock, it
causes issue in this scenario:
* the VM host send data to the guest, and it's splitted into multiple
VM packets
* sk_data_ready is called and epoll returns, notifying the userspace
that the socket is ready
* userspace call recvmsg with a buffer, and it's partially filled
* userspace assumes that the stream socket is depleted, and if new data
arrives epoll will notify it again.
* kernel always considers the socket to be ready, and since it's in
edge-trigger mode, the epoll instance will never be notified again.
This different realisation of the readiness causes the userspace to
block forever.
[0] https://github.com/nbdd0121/wsld/issues/32
[1] https://man7.org/linux/man-pages/man7/epoll.7.html#:~:text=For%20stream%2Doriented%20files
[2] https://github.com/tokio-rs/tokio/pull/4840
^ permalink raw reply
* Re: [PATCH 03/12] sysfb: Do not include <linux/screen_info.h> from sysfb header
From: Javier Martinez Canillas @ 2023-07-04 16:26 UTC (permalink / raw)
To: Thomas Zimmermann, arnd, deller, daniel, airlied
Cc: linux-kernel, linux-alpha, linux-arm-kernel, linux-efi,
linux-csky, linux-hexagon, linux-ia64, loongarch, linux-mips,
linuxppc-dev, linux-riscv, linux-sh, sparclinux, dri-devel,
linux-hyperv, linux-fbdev, linux-staging, linux-arch,
Thomas Zimmermann, Ard Biesheuvel, Hans de Goede
In-Reply-To: <20230629121952.10559-4-tzimmermann@suse.de>
Thomas Zimmermann <tzimmermann@suse.de> writes:
> The header file <linux/sysfb.h> does not need anything from
> <linux/screen_info.h>. Declare struct screen_info and remove
> the include statements.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Hans de Goede <hdegoede@redhat.com>
> Cc: Javier Martinez Canillas <javierm@redhat.com>
> ---
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
--
Best regards,
Javier Martinez Canillas
Core Platforms
Red Hat
^ permalink raw reply
* Re: [PATCH 05/12] arch: Remove trailing whitespaces
From: Javier Martinez Canillas @ 2023-07-04 16:27 UTC (permalink / raw)
To: Thomas Zimmermann, arnd, deller, daniel, airlied
Cc: linux-hyperv, linux-efi, linux-ia64, linux-sh, Peter Zijlstra,
linux-fbdev, dri-devel, linux-mips, Rich Felker, sparclinux,
linux-riscv, linux-arch, Yoshinori Sato, linux-hexagon,
linux-staging, linux-csky, Geert Uytterhoeven, Zi Yan,
Anshuman Khandual, Niklas Schnelle, loongarch,
John Paul Adrian Glaubitz, linux-arm-kernel, Arnd Bergmann,
linux-kernel, Mike Rapoport (IBM), Thomas Zimmermann, linux-alpha,
Andrew Morton, linuxppc-dev, Kirill A. Shutemov
In-Reply-To: <20230629121952.10559-6-tzimmermann@suse.de>
Thomas Zimmermann <tzimmermann@suse.de> writes:
> Fix coding style. No functional changes.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
> Cc: Rich Felker <dalias@libc.org>
> Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Arnd Bergmann <arnd@kernel.org>
> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> Cc: Anshuman Khandual <anshuman.khandual@arm.com>
> Cc: Niklas Schnelle <schnelle@linux.ibm.com>
> Cc: Zi Yan <ziy@nvidia.com>
> Cc: "Mike Rapoport (IBM)" <rppt@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> ---
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
--
Best regards,
Javier Martinez Canillas
Core Platforms
Red Hat
^ permalink raw reply
* Re: [PATCH 04/12] staging/sm750fb: Do not include <linux/screen_info.h>
From: Javier Martinez Canillas @ 2023-07-04 16:27 UTC (permalink / raw)
To: Thomas Zimmermann, arnd, deller, daniel, airlied
Cc: linux-arch, linux-hyperv, linux-efi, linux-ia64,
Thomas Zimmermann, linux-sh, linux-hexagon, linux-staging,
linux-kernel, linux-csky, linux-mips, linux-fbdev, dri-devel,
loongarch, linux-alpha, sparclinux, linux-riscv, linuxppc-dev,
Sudip Mukherjee, linux-arm-kernel, Teddy Wang
In-Reply-To: <20230629121952.10559-5-tzimmermann@suse.de>
Thomas Zimmermann <tzimmermann@suse.de> writes:
> The sm750fb driver does not need anything from <linux/screen_info.h>.
> Remove the include statements.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
> Cc: Teddy Wang <teddy.wang@siliconmotion.com>
> ---
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
--
Best regards,
Javier Martinez Canillas
Core Platforms
Red Hat
^ permalink raw reply
* Re: [PATCH 02/12] fbdev/sm712fb: Do not include <linux/screen_info.h>
From: Javier Martinez Canillas @ 2023-07-04 16:25 UTC (permalink / raw)
To: Thomas Zimmermann, arnd, deller, daniel, airlied
Cc: linux-arch, linux-hyperv, linux-efi, linux-ia64,
Thomas Zimmermann, linux-sh, linux-hexagon, linux-staging,
linux-kernel, linux-csky, linux-mips, linux-fbdev, dri-devel,
loongarch, linux-alpha, sparclinux, linux-riscv, linuxppc-dev,
Sudip Mukherjee, linux-arm-kernel, Teddy Wang
In-Reply-To: <20230629121952.10559-3-tzimmermann@suse.de>
Thomas Zimmermann <tzimmermann@suse.de> writes:
> Sm712fb's dependency on <linux/screen_info.h> is artificial in that
> it only uses struct screen_info for its internals. Replace the use of
> struct screen_info with a custom data structure and remove the include
> of <linux/screen_info.h>.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
> Cc: Teddy Wang <teddy.wang@siliconmotion.com>
> Cc: Helge Deller <deller@gmx.de>
> ---
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
--
Best regards,
Javier Martinez Canillas
Core Platforms
Red Hat
^ permalink raw reply
* Re: [PATCH 01/12] efi: Do not include <linux/screen_info.h> from EFI header
From: Javier Martinez Canillas @ 2023-07-04 16:23 UTC (permalink / raw)
To: Thomas Zimmermann, arnd, deller, daniel, airlied
Cc: linux-hyperv, linux-efi, linux-ia64, linux-sh, Catalin Marinas,
linux-fbdev, dri-devel, linux-mips, sparclinux, linux-riscv,
Will Deacon, Ard Biesheuvel, linux-arch, linux-hexagon,
linux-staging, Russell King, linux-csky, loongarch,
linux-arm-kernel, linux-kernel, Thomas Zimmermann, linux-alpha,
linuxppc-dev
In-Reply-To: <20230629121952.10559-2-tzimmermann@suse.de>
Thomas Zimmermann <tzimmermann@suse.de> writes:
> The header file <linux/efi.h> does not need anything from
> <linux/screen_info.h>. Declare struct screen_info and remove
> the include statements. Update a number of source files that
> require struct screen_info's definition.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> ---
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
--
Best regards,
Javier Martinez Canillas
Core Platforms
Red Hat
^ permalink raw reply
* RE: [PATCH V2 9/9] x86/hyperv: Add hyperv-specific handling for VMMCALL under SEV-ES
From: Michael Kelley (LINUX) @ 2023-07-04 14:25 UTC (permalink / raw)
To: Tianyu Lan, KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org,
Dexuan Cui, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
daniel.lezcano@linaro.org, arnd@arndb.de
Cc: Tianyu Lan, linux-arch@vger.kernel.org,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
vkuznets@redhat.com
In-Reply-To: <20230627032248.2170007-10-ltykernel@gmail.com>
From: Tianyu Lan <ltykernel@gmail.com> Sent: Monday, June 26, 2023 8:23 PM
>
> Add Hyperv-specific handling for faults caused by VMMCALL
> instructions.
>
> Signed-off-by: Tianyu Lan <tiala@microsoft.com>
> ---
> arch/x86/kernel/cpu/mshyperv.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index 8e1d9ed6a1e0..ba9a3a65f664 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -32,6 +32,7 @@
> #include <asm/nmi.h>
> #include <clocksource/hyperv_timer.h>
> #include <asm/numa.h>
> +#include <asm/svm.h>
>
> /* Is Linux running as the root partition? */
> bool hv_root_partition;
> @@ -577,6 +578,20 @@ static bool __init ms_hyperv_msi_ext_dest_id(void)
> return eax & HYPERV_VS_PROPERTIES_EAX_EXTENDED_IOAPIC_RTE;
> }
>
> +static void hv_sev_es_hcall_prepare(struct ghcb *ghcb, struct pt_regs *regs)
> +{
> + /* RAX and CPL are already in the GHCB */
> + ghcb_set_rcx(ghcb, regs->cx);
> + ghcb_set_rdx(ghcb, regs->dx);
> + ghcb_set_r8(ghcb, regs->r8);
> +}
> +
> +static bool hv_sev_es_hcall_finish(struct ghcb *ghcb, struct pt_regs *regs)
> +{
> + /* No checking of the return state needed */
> + return true;
> +}
> +
> const __initconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
> .name = "Microsoft Hyper-V",
> .detect = ms_hyperv_platform,
> @@ -584,4 +599,6 @@ const __initconst struct hypervisor_x86 x86_hyper_ms_hyperv
> = {
> .init.x2apic_available = ms_hyperv_x2apic_available,
> .init.msi_ext_dest_id = ms_hyperv_msi_ext_dest_id,
> .init.init_platform = ms_hyperv_init_platform,
> + .runtime.sev_es_hcall_prepare = hv_sev_es_hcall_prepare,
> + .runtime.sev_es_hcall_finish = hv_sev_es_hcall_finish,
> };
> --
> 2.25.1
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
^ permalink raw reply
* RE: [PATCH V2 8/9] x86/hyperv: Add smp support for SEV-SNP guest
From: Michael Kelley (LINUX) @ 2023-07-04 14:24 UTC (permalink / raw)
To: Tianyu Lan, KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org,
Dexuan Cui, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
daniel.lezcano@linaro.org, arnd@arndb.de
Cc: Tianyu Lan, linux-arch@vger.kernel.org,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
vkuznets@redhat.com
In-Reply-To: <20230627032248.2170007-9-ltykernel@gmail.com>
From: Tianyu Lan <ltykernel@gmail.com> Sent: Monday, June 26, 2023 8:23 PM
>
> In the AMD SEV-SNP guest, AP needs to be started up via sev es
> save area and Hyper-V requires to call HVCALL_START_VP hypercall
> to pass the gpa of sev es save area with AP's vp index and VTL(Virtual
> trust level) parameters. Override wakeup_secondary_cpu_64 callback
> with hv_snp_boot_ap.
>
> Signed-off-by: Tianyu Lan <tiala@microsoft.com>
> ---
> arch/x86/hyperv/ivm.c | 95 +++++++++++++++++++++++++++++++
> arch/x86/include/asm/mshyperv.h | 9 +++
> arch/x86/kernel/cpu/mshyperv.c | 13 ++++-
> include/asm-generic/hyperv-tlfs.h | 1 +
> 4 files changed, 116 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
> index b1639ec07155..9b307f99b540 100644
> --- a/arch/x86/hyperv/ivm.c
> +++ b/arch/x86/hyperv/ivm.c
> @@ -22,11 +22,15 @@
> #include <asm/sev.h>
> #include <asm/realmode.h>
> #include <asm/e820/api.h>
> +#include <asm/desc.h>
>
> #ifdef CONFIG_AMD_MEM_ENCRYPT
>
> #define GHCB_USAGE_HYPERV_CALL 1
>
> +static u8 ap_start_input_arg[PAGE_SIZE] __bss_decrypted __aligned(PAGE_SIZE);
> +static u8 ap_start_stack[PAGE_SIZE] __aligned(PAGE_SIZE);
> +
> union hv_ghcb {
> struct ghcb ghcb;
> struct {
> @@ -449,6 +453,97 @@ __init void hv_sev_init_mem_and_cpu(void)
> }
> }
>
> +#define hv_populate_vmcb_seg(seg, gdtr_base) \
> +do { \
> + if (seg.selector) { \
> + seg.base = 0; \
> + seg.limit = HV_AP_SEGMENT_LIMIT; \
> + seg.attrib = *(u16 *)(gdtr_base + seg.selector + 5); \
> + seg.attrib = (seg.attrib & 0xFF) | ((seg.attrib >> 4) & 0xF00); \
> + } \
> +} while (0) \
> +
> +int hv_snp_boot_ap(int cpu, unsigned long start_ip)
> +{
> + struct sev_es_save_area *vmsa = (struct sev_es_save_area *)
> + __get_free_page(GFP_KERNEL | __GFP_ZERO);
> + struct desc_ptr gdtr;
> + u64 ret, rmp_adjust, retry = 5;
> + struct hv_enable_vp_vtl *start_vp_input;
> + unsigned long flags;
> +
> + native_store_gdt(&gdtr);
> +
> + vmsa->gdtr.base = gdtr.address;
> + vmsa->gdtr.limit = gdtr.size;
> +
> + asm volatile("movl %%es, %%eax;" : "=a" (vmsa->es.selector));
> + hv_populate_vmcb_seg(vmsa->es, vmsa->gdtr.base);
> +
> + asm volatile("movl %%cs, %%eax;" : "=a" (vmsa->cs.selector));
> + hv_populate_vmcb_seg(vmsa->cs, vmsa->gdtr.base);
> +
> + asm volatile("movl %%ss, %%eax;" : "=a" (vmsa->ss.selector));
> + hv_populate_vmcb_seg(vmsa->ss, vmsa->gdtr.base);
> +
> + asm volatile("movl %%ds, %%eax;" : "=a" (vmsa->ds.selector));
> + hv_populate_vmcb_seg(vmsa->ds, vmsa->gdtr.base);
> +
> + vmsa->efer = native_read_msr(MSR_EFER);
> +
> + asm volatile("movq %%cr4, %%rax;" : "=a" (vmsa->cr4));
> + asm volatile("movq %%cr3, %%rax;" : "=a" (vmsa->cr3));
> + asm volatile("movq %%cr0, %%rax;" : "=a" (vmsa->cr0));
> +
> + vmsa->xcr0 = 1;
> + vmsa->g_pat = HV_AP_INIT_GPAT_DEFAULT;
> + vmsa->rip = (u64)secondary_startup_64_no_verify;
> + vmsa->rsp = (u64)&ap_start_stack[PAGE_SIZE];
> +
> + /*
> + * Set the SNP-specific fields for this VMSA:
> + * VMPL level
> + * SEV_FEATURES (matches the SEV STATUS MSR right shifted 2 bits)
> + */
> + vmsa->vmpl = 0;
> + vmsa->sev_features = sev_status >> 2;
> +
> + /*
> + * Running at VMPL0 allows the kernel to change the VMSA bit for a page
> + * using the RMPADJUST instruction. However, for the instruction to
> + * succeed it must target the permissions of a lesser privileged
> + * (higher numbered) VMPL level, so use VMPL1 (refer to the RMPADJUST
> + * instruction in the AMD64 APM Volume 3).
> + */
> + rmp_adjust = RMPADJUST_VMSA_PAGE_BIT | 1;
> + ret = rmpadjust((unsigned long)vmsa, RMP_PG_SIZE_4K,
> + rmp_adjust);
> + if (ret != 0) {
> + pr_err("RMPADJUST(%llx) failed: %llx\n", (u64)vmsa, ret);
> + return ret;
> + }
> +
> + local_irq_save(flags);
> + start_vp_input =
> + (struct hv_enable_vp_vtl *)ap_start_input_arg;
> + memset(start_vp_input, 0, sizeof(*start_vp_input));
> + start_vp_input->partition_id = -1;
> + start_vp_input->vp_index = cpu;
> + start_vp_input->target_vtl.target_vtl = ms_hyperv.vtl;
> + *(u64 *)&start_vp_input->vp_context = __pa(vmsa) | 1;
> +
> + do {
> + ret = hv_do_hypercall(HVCALL_START_VP,
> + start_vp_input, NULL);
> + } while (hv_result(ret) == HV_STATUS_TIME_OUT && retry--);
> +
> + local_irq_restore(flags);
> +
> + if (!hv_result_success(ret))
> + pr_err("HvCallStartVirtualProcessor failed: %llx\n", ret);
> + return ret;
> +}
> +
> void __init hv_vtom_init(void)
> {
> /*
> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
> index 7a9a6cdc2ae9..804c67475054 100644
> --- a/arch/x86/include/asm/mshyperv.h
> +++ b/arch/x86/include/asm/mshyperv.h
> @@ -65,6 +65,13 @@ struct memory_map_entry {
> u32 reserved;
> };
>
> +/*
> + * DEFAULT INIT GPAT and SEGMENT LIMIT value in struct VMSA
> + * to start AP in enlightened SEV guest.
> + */
> +#define HV_AP_INIT_GPAT_DEFAULT 0x0007040600070406ULL
> +#define HV_AP_SEGMENT_LIMIT 0xffffffff
> +
> int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
> int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
> int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
> @@ -271,6 +278,7 @@ bool hv_ghcb_negotiate_protocol(void);
> void __noreturn hv_ghcb_terminate(unsigned int set, unsigned int reason);
> void hv_vtom_init(void);
> void hv_sev_init_mem_and_cpu(void);
> +int hv_snp_boot_ap(int cpu, unsigned long start_ip);
> #else
> static inline void hv_ghcb_msr_write(u64 msr, u64 value) {}
> static inline void hv_ghcb_msr_read(u64 msr, u64 *value) {}
> @@ -278,6 +286,7 @@ static inline bool hv_ghcb_negotiate_protocol(void) { return false; }
> static inline void hv_ghcb_terminate(unsigned int set, unsigned int reason) {}
> static inline void hv_vtom_init(void) {}
> static inline void hv_sev_init_mem_and_cpu(void) {}
> +static int hv_snp_boot_ap(int cpu, unsigned long start_ip) {}
> #endif
>
> extern bool hv_isolation_type_snp(void);
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index d3bb921ee7fe..8e1d9ed6a1e0 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -295,6 +295,16 @@ static void __init hv_smp_prepare_cpus(unsigned int
> max_cpus)
>
> native_smp_prepare_cpus(max_cpus);
>
> + /*
> + * Override wakeup_secondary_cpu_64 callback for SEV-SNP
> + * enlightened guest.
> + */
> + if (hv_isolation_type_en_snp())
> + apic->wakeup_secondary_cpu_64 = hv_snp_boot_ap;
> +
> + if (!hv_root_partition)
> + return;
> +
> #ifdef CONFIG_X86_64
> for_each_present_cpu(i) {
> if (i == 0)
> @@ -502,8 +512,7 @@ static void __init ms_hyperv_init_platform(void)
>
> # ifdef CONFIG_SMP
> smp_ops.smp_prepare_boot_cpu = hv_smp_prepare_boot_cpu;
> - if (hv_root_partition)
> - smp_ops.smp_prepare_cpus = hv_smp_prepare_cpus;
> + smp_ops.smp_prepare_cpus = hv_smp_prepare_cpus;
> # endif
>
> /*
> diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h
> index f4e4cc4f965f..fdac4a1714ec 100644
> --- a/include/asm-generic/hyperv-tlfs.h
> +++ b/include/asm-generic/hyperv-tlfs.h
> @@ -223,6 +223,7 @@ enum HV_GENERIC_SET_FORMAT {
> #define HV_STATUS_INVALID_PORT_ID 17
> #define HV_STATUS_INVALID_CONNECTION_ID 18
> #define HV_STATUS_INSUFFICIENT_BUFFERS 19
> +#define HV_STATUS_TIME_OUT 120
> #define HV_STATUS_VTL_ALREADY_ENABLED 134
>
> /*
> --
> 2.25.1
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
^ permalink raw reply
* RE: [PATCH V2 7/9] x86/hyperv: Initialize cpu and memory for SEV-SNP enlightened guest
From: Michael Kelley (LINUX) @ 2023-07-04 14:23 UTC (permalink / raw)
To: Tianyu Lan, KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org,
Dexuan Cui, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
daniel.lezcano@linaro.org, arnd@arndb.de
Cc: Tianyu Lan, linux-arch@vger.kernel.org,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
vkuznets@redhat.com
In-Reply-To: <20230627032248.2170007-8-ltykernel@gmail.com>
From: Tianyu Lan <ltykernel@gmail.com> Sent: Monday, June 26, 2023 8:23 PM
>
> Hyper-V enlightened guest doesn't have boot loader support.
> Boot Linux kernel directly from hypervisor with data (kernel
> image, initrd and parameter page) and memory for boot up that
> is initialized via AMD SEV PSP protocol (Please reference
> Section 4.5 Launching a Guest of [1]).
>
> Kernel needs to read processor and memory info from EN_SEV_
> SNP_PROCESSOR/MEM_INFO_ADDR address which are populated by
> Hyper-V. The these data is prepared by hypervisor via SNP_
s/The these data/The data/
> LAUNCH_UPDATE with page type SNP_PAGE_TYPE_UNMEASURED and
> Initialize smp cpu related ops, validate system memory and
> add them into e820 table.
>
> [1]: https://www.amd.com/system/files/TechDocs/56860.pdf
> Signed-off-by: Tianyu Lan <tiala@microsoft.com>
> ---
> arch/x86/hyperv/ivm.c | 93 +++++++++++++++++++++++++++++++++
> arch/x86/include/asm/mshyperv.h | 17 ++++++
> arch/x86/kernel/cpu/mshyperv.c | 3 ++
> 3 files changed, 113 insertions(+)
>
> diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
> index 5d3ee3124e00..b1639ec07155 100644
> --- a/arch/x86/hyperv/ivm.c
> +++ b/arch/x86/hyperv/ivm.c
> @@ -17,6 +17,11 @@
> #include <asm/mem_encrypt.h>
> #include <asm/mshyperv.h>
> #include <asm/hypervisor.h>
> +#include <asm/coco.h>
> +#include <asm/io_apic.h>
> +#include <asm/sev.h>
> +#include <asm/realmode.h>
> +#include <asm/e820/api.h>
>
> #ifdef CONFIG_AMD_MEM_ENCRYPT
>
> @@ -57,6 +62,8 @@ union hv_ghcb {
>
> static u16 hv_ghcb_version __ro_after_init;
>
> +static u32 processor_count;
> +
> u64 hv_ghcb_hypercall(u64 control, void *input, void *output, u32 input_size)
> {
> union hv_ghcb *hv_ghcb;
> @@ -356,6 +363,92 @@ static bool hv_is_private_mmio(u64 addr)
> return false;
> }
>
> +static __init void hv_snp_get_smp_config(unsigned int early)
> +{
> + /*
> + * The "early" parameter can be true only if old-style AMD
> + * Opteron NUMA detection is enabled, which should never be
> + * the case for an SEV-SNP guest. See CONFIG_AMD_NUMA.
> + * For safety, just do nothing if "early" is true.
> + */
> + if (early)
> + return;
> +
> + /*
> + * There is no firmware and ACPI MADT table support in
> + * in the Hyper-V SEV-SNP enlightened guest. Set smp
> + * related config variable here.
> + */
> + while (num_processors < processor_count) {
> + early_per_cpu(x86_cpu_to_apicid, num_processors) = num_processors;
> + early_per_cpu(x86_bios_cpu_apicid, num_processors) = num_processors;
> + physid_set(num_processors, phys_cpu_present_map);
> + set_cpu_possible(num_processors, true);
> + set_cpu_present(num_processors, true);
> + num_processors++;
> + }
> +}
> +
> +__init void hv_sev_init_mem_and_cpu(void)
> +{
> + struct memory_map_entry *entry;
> + struct e820_entry *e820_entry;
> + u64 e820_end;
> + u64 ram_end;
> + u64 page;
> +
> + /*
> + * Hyper-V enlightened snp guest boots kernel
> + * directly without bootloader. So roms, bios
> + * regions and reserve resources are not available.
> + * Set these callback to NULL.
> + */
> + x86_platform.legacy.rtc = 0;
> + x86_platform.legacy.reserve_bios_regions = 0;
> + x86_platform.set_wallclock = set_rtc_noop;
> + x86_platform.get_wallclock = get_rtc_noop;
> + x86_init.resources.probe_roms = x86_init_noop;
> + x86_init.resources.reserve_resources = x86_init_noop;
> + x86_init.mpparse.find_smp_config = x86_init_noop;
> + x86_init.mpparse.get_smp_config = hv_snp_get_smp_config;
> +
> + /*
> + * Hyper-V SEV-SNP enlightened guest doesn't support ioapic
> + * and legacy APIC page read/write. Switch to hv apic here.
> + */
> + disable_ioapic_support();
> +
> + /* Get processor and mem info. */
> + processor_count = *(u32 *)__va(EN_SEV_SNP_PROCESSOR_INFO_ADDR);
> + entry = (struct memory_map_entry *)__va(EN_SEV_SNP_MEM_INFO_ADDR);
> +
> + /*
> + * There is no bootloader/EFI firmware in the SEV SNP guest.
> + * E820 table in the memory just describes memory for kernel,
> + * ACPI table, cmdline, boot params and ramdisk. The dynamic
> + * data(e.g, vcpu number and the rest memory layout) needs to
> + * be read from EN_SEV_SNP_PROCESSOR_INFO_ADDR.
> + */
> + for (; entry->numpages != 0; entry++) {
> + e820_entry = &e820_table->entries[
> + e820_table->nr_entries - 1];
> + e820_end = e820_entry->addr + e820_entry->size;
> + ram_end = (entry->starting_gpn +
> + entry->numpages) * PAGE_SIZE;
> +
> + if (e820_end < entry->starting_gpn * PAGE_SIZE)
> + e820_end = entry->starting_gpn * PAGE_SIZE;
> +
> + if (e820_end < ram_end) {
> + pr_info("Hyper-V: add e820 entry [mem %#018Lx-%#018Lx]\n", e820_end, ram_end - 1);
> + e820__range_add(e820_end, ram_end - e820_end,
> + E820_TYPE_RAM);
> + for (page = e820_end; page < ram_end; page += PAGE_SIZE)
> + pvalidate((unsigned long)__va(page), RMP_PG_SIZE_4K, true);
> + }
> + }
> +}
> +
> void __init hv_vtom_init(void)
> {
> /*
> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
> index d859d7c5f5e8..7a9a6cdc2ae9 100644
> --- a/arch/x86/include/asm/mshyperv.h
> +++ b/arch/x86/include/asm/mshyperv.h
> @@ -50,6 +50,21 @@ extern bool hv_isolation_type_en_snp(void);
>
> extern union hv_ghcb * __percpu *hv_ghcb_pg;
>
> +/*
> + * Hyper-V puts processor and memory layout info
> + * to this address in SEV-SNP enlightened guest.
> + */
> +#define EN_SEV_SNP_PROCESSOR_INFO_ADDR 0x802000
> +#define EN_SEV_SNP_MEM_INFO_ADDR 0x802018
> +
> +struct memory_map_entry {
> + u64 starting_gpn;
> + u64 numpages;
> + u16 type;
> + u16 flags;
> + u32 reserved;
> +};
> +
> int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
> int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
> int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
> @@ -255,12 +270,14 @@ void hv_ghcb_msr_read(u64 msr, u64 *value);
> bool hv_ghcb_negotiate_protocol(void);
> void __noreturn hv_ghcb_terminate(unsigned int set, unsigned int reason);
> void hv_vtom_init(void);
> +void hv_sev_init_mem_and_cpu(void);
> #else
> static inline void hv_ghcb_msr_write(u64 msr, u64 value) {}
> static inline void hv_ghcb_msr_read(u64 msr, u64 *value) {}
> static inline bool hv_ghcb_negotiate_protocol(void) { return false; }
> static inline void hv_ghcb_terminate(unsigned int set, unsigned int reason) {}
> static inline void hv_vtom_init(void) {}
> +static inline void hv_sev_init_mem_and_cpu(void) {}
> #endif
>
> extern bool hv_isolation_type_snp(void);
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index 5398fb2f4d39..d3bb921ee7fe 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -529,6 +529,9 @@ static void __init ms_hyperv_init_platform(void)
> if (!(ms_hyperv.features & HV_ACCESS_TSC_INVARIANT))
> mark_tsc_unstable("running on Hyper-V");
>
> + if (hv_isolation_type_en_snp())
> + hv_sev_init_mem_and_cpu();
> +
> hardlockup_detector_disable();
> }
>
> --
> 2.25.1
Modulo spurious word in the commit message,
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
^ permalink raw reply
* RE: [PATCH V2 6/9] clocksource: hyper-v: Mark hyperv tsc page unencrypted in sev-snp enlightened guest
From: Michael Kelley (LINUX) @ 2023-07-04 14:19 UTC (permalink / raw)
To: Tianyu Lan, KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org,
Dexuan Cui, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
daniel.lezcano@linaro.org, arnd@arndb.de
Cc: Tianyu Lan, linux-arch@vger.kernel.org,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
vkuznets@redhat.com
In-Reply-To: <20230627032248.2170007-7-ltykernel@gmail.com>
From: Tianyu Lan <ltykernel@gmail.com> Sent: Monday, June 26, 2023 8:23 PM
>
> Hyper-V tsc page is shared with hypervisor and mark the page
> unencrypted in sev-snp enlightened guest when it's used.
>
> Signed-off-by: Tianyu Lan <tiala@microsoft.com>
> ---
> drivers/clocksource/hyperv_timer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c
> index bcd9042a0c9f..66e29a19770b 100644
> --- a/drivers/clocksource/hyperv_timer.c
> +++ b/drivers/clocksource/hyperv_timer.c
> @@ -376,7 +376,7 @@ EXPORT_SYMBOL_GPL(hv_stimer_global_cleanup);
> static union {
> struct ms_hyperv_tsc_page page;
> u8 reserved[PAGE_SIZE];
> -} tsc_pg __aligned(PAGE_SIZE);
> +} tsc_pg __bss_decrypted __aligned(PAGE_SIZE);
>
> static struct ms_hyperv_tsc_page *tsc_page = &tsc_pg.page;
> static unsigned long tsc_pfn;
> --
> 2.25.1
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
^ permalink raw reply
* RE: [PATCH V2 4/9] drivers: hv: Mark percpu hvcall input arg page unencrypted in SEV-SNP enlightened guest
From: Michael Kelley (LINUX) @ 2023-07-04 14:19 UTC (permalink / raw)
To: Tianyu Lan, KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org,
Dexuan Cui, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
daniel.lezcano@linaro.org, arnd@arndb.de
Cc: Tianyu Lan, linux-arch@vger.kernel.org,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
vkuznets@redhat.com
In-Reply-To: <20230627032248.2170007-5-ltykernel@gmail.com>
From: Tianyu Lan <ltykernel@gmail.com> Sent: Monday, June 26, 2023 8:23 PM
>
> Hypervisor needs to access input arg, VMBus synic event and
> message pages. Mark these pages unencrypted in the SEV-SNP
> guest and free them only if they have been marked encrypted
> successfully.
>
> Signed-off-by: Tianyu Lan <tiala@microsoft.com>
> ---
> drivers/hv/hv.c | 57 +++++++++++++++++++++++++++++++++++++++---
> drivers/hv/hv_common.c | 13 ++++++++++
> 2 files changed, 67 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
> index de6708dbe0df..ec6e35a0d9bf 100644
> --- a/drivers/hv/hv.c
> +++ b/drivers/hv/hv.c
> @@ -20,6 +20,7 @@
> #include <linux/interrupt.h>
> #include <clocksource/hyperv_timer.h>
> #include <asm/mshyperv.h>
> +#include <linux/set_memory.h>
> #include "hyperv_vmbus.h"
>
> /* The one and only */
> @@ -78,7 +79,7 @@ int hv_post_message(union hv_connection_id connection_id,
>
> int hv_synic_alloc(void)
> {
> - int cpu;
> + int cpu, ret = -ENOMEM;
> struct hv_per_cpu_context *hv_cpu;
>
> /*
> @@ -123,26 +124,76 @@ int hv_synic_alloc(void)
> goto err;
> }
> }
> +
> + if (hv_isolation_type_en_snp()) {
> + ret = set_memory_decrypted((unsigned long)
> + hv_cpu->synic_message_page, 1);
> + if (ret) {
> + pr_err("Failed to decrypt SYNIC msg page: %d\n", ret);
> + hv_cpu->synic_message_page = NULL;
> +
> + /*
> + * Free the event page here so that hv_synic_free()
> + * won't later try to re-encrypt it.
> + */
> + free_page((unsigned long)hv_cpu->synic_event_page);
> + hv_cpu->synic_event_page = NULL;
> + goto err;
> + }
> +
> + ret = set_memory_decrypted((unsigned long)
> + hv_cpu->synic_event_page, 1);
> + if (ret) {
> + pr_err("Failed to decrypt SYNIC event page: %d\n", ret);
> + hv_cpu->synic_event_page = NULL;
> + goto err;
> + }
> +
> + memset(hv_cpu->synic_message_page, 0, PAGE_SIZE);
> + memset(hv_cpu->synic_event_page, 0, PAGE_SIZE);
> + }
> }
>
> return 0;
> +
> err:
> /*
> * Any memory allocations that succeeded will be freed when
> * the caller cleans up by calling hv_synic_free()
> */
> - return -ENOMEM;
> + return ret;
> }
>
>
> void hv_synic_free(void)
> {
> - int cpu;
> + int cpu, ret;
>
> for_each_present_cpu(cpu) {
> struct hv_per_cpu_context *hv_cpu
> = per_cpu_ptr(hv_context.cpu_context, cpu);
>
> + /* It's better to leak the page if the encryption fails. */
> + if (hv_isolation_type_en_snp()) {
> + if (hv_cpu->synic_message_page) {
> + ret = set_memory_encrypted((unsigned long)
> + hv_cpu->synic_message_page, 1);
> + if (ret) {
> + pr_err("Failed to encrypt SYNIC msg page: %d\n", ret);
> + hv_cpu->synic_message_page = NULL;
> + }
> + }
> +
> + if (hv_cpu->synic_event_page) {
> + ret = set_memory_encrypted((unsigned long)
> + hv_cpu->synic_event_page, 1);
> + if (ret) {
> + pr_err("Failed to encrypt SYNIC event page: %d\n", ret);
> + hv_cpu->synic_event_page = NULL;
> + }
> + }
> + }
> +
> free_page((unsigned long)hv_cpu->synic_event_page);
> free_page((unsigned long)hv_cpu->synic_message_page);
> }
> diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> index 4b4aa53c34c2..2d43ba2bc925 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -24,6 +24,7 @@
> #include <linux/kmsg_dump.h>
> #include <linux/slab.h>
> #include <linux/dma-map-ops.h>
> +#include <linux/set_memory.h>
> #include <asm/hyperv-tlfs.h>
> #include <asm/mshyperv.h>
>
> @@ -359,6 +360,7 @@ int hv_common_cpu_init(unsigned int cpu)
> u64 msr_vp_index;
> gfp_t flags;
> int pgcount = hv_root_partition ? 2 : 1;
> + int ret;
>
> /* hv_cpu_init() can be called with IRQs disabled from hv_resume() */
> flags = irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL;
> @@ -378,6 +380,17 @@ int hv_common_cpu_init(unsigned int cpu)
> outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg);
> *outputarg = (char *)(*inputarg) + HV_HYP_PAGE_SIZE;
> }
> +
> + if (hv_isolation_type_en_snp()) {
> + ret = set_memory_decrypted((unsigned long)*inputarg, pgcount);
> + if (ret) {
> + kfree(*inputarg);
> + *inputarg = NULL;
> + return ret;
> + }
> +
> + memset(*inputarg, 0x00, pgcount * PAGE_SIZE);
> + }
> }
>
> msr_vp_index = hv_get_register(HV_REGISTER_VP_INDEX);
> --
> 2.25.1
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
^ permalink raw reply
* RE: [PATCH V2 3/9] x86/hyperv: Mark Hyper-V vp assist page unencrypted in SEV-SNP enlightened guest
From: Michael Kelley (LINUX) @ 2023-07-04 14:18 UTC (permalink / raw)
To: Tianyu Lan, KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org,
Dexuan Cui, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
daniel.lezcano@linaro.org, arnd@arndb.de
Cc: Tianyu Lan, linux-arch@vger.kernel.org,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
vkuznets@redhat.com
In-Reply-To: <20230627032248.2170007-4-ltykernel@gmail.com>
From: Tianyu Lan <ltykernel@gmail.com> Sent: Monday, June 26, 2023 8:23 PM
>
> hv vp assist page needs to be shared between SEV-SNP guest and Hyper-V.
> So mark the page unencrypted in the SEV-SNP guest.
>
> Signed-off-by: Tianyu Lan <tiala@microsoft.com>
> ---
> arch/x86/hyperv/hv_init.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
> index 1ba367a9686e..b004370d3b01 100644
> --- a/arch/x86/hyperv/hv_init.c
> +++ b/arch/x86/hyperv/hv_init.c
> @@ -18,6 +18,7 @@
> #include <asm/hyperv-tlfs.h>
> #include <asm/mshyperv.h>
> #include <asm/idtentry.h>
> +#include <asm/set_memory.h>
> #include <linux/kexec.h>
> #include <linux/version.h>
> #include <linux/vmalloc.h>
> @@ -106,8 +107,21 @@ static int hv_cpu_init(unsigned int cpu)
> * in hv_cpu_die(), otherwise a CPU may not be stopped in the
> * case of CPU offlining and the VM will hang.
> */
> - if (!*hvp)
> + if (!*hvp) {
> *hvp = __vmalloc(PAGE_SIZE, GFP_KERNEL | __GFP_ZERO);
> +
> + /*
> + * Hyper-V should never specify a VM that is a Confidential
> + * VM and also running in the root partition. Root partition
> + * is blocked to run in Confidential VM. So only decrypt assist
> + * page in non-root partition here.
> + */
> + if (*hvp && hv_isolation_type_en_snp()) {
> + WARN_ON_ONCE(set_memory_decrypted((unsigned
> long)(*hvp), 1));
> + memset(*hvp, 0, PAGE_SIZE);
> + }
> + }
> +
> if (*hvp)
> msr.pfn = vmalloc_to_pfn(*hvp);
>
> --
> 2.25.1
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
^ permalink raw reply
* RE: [PATCH V2 2/9] x86/hyperv: Set Virtual Trust Level in VMBus init message
From: Michael Kelley (LINUX) @ 2023-07-04 14:18 UTC (permalink / raw)
To: Tianyu Lan, KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org,
Dexuan Cui, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
daniel.lezcano@linaro.org, arnd@arndb.de
Cc: Tianyu Lan, linux-arch@vger.kernel.org,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
vkuznets@redhat.com
In-Reply-To: <20230627032248.2170007-3-ltykernel@gmail.com>
From: Tianyu Lan <ltykernel@gmail.com> Sent: Monday, June 26, 2023 8:23 PM
>
> SEV-SNP guest provides vtl(Virtual Trust Level) and
> get it from Hyper-V hvcall via register hvcall HVCALL_
> GET_VP_REGISTERS.
>
> During initialization of VMBus, vtl needs to be set in the
> VMBus init message.
I had suggested a revised version of the commit message, which you
agreed to use. But this is still the old commit message.
Michael
>
> Signed-off-by: Tianyu Lan <tiala@microsoft.com>
> ---
> arch/x86/hyperv/hv_init.c | 36 ++++++++++++++++++++++++++++++
> arch/x86/include/asm/hyperv-tlfs.h | 7 ++++++
> drivers/hv/connection.c | 1 +
> include/asm-generic/mshyperv.h | 1 +
> include/linux/hyperv.h | 4 ++--
> 5 files changed, 47 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
> index 6c04b52f139b..1ba367a9686e 100644
> --- a/arch/x86/hyperv/hv_init.c
> +++ b/arch/x86/hyperv/hv_init.c
> @@ -378,6 +378,40 @@ static void __init hv_get_partition_id(void)
> local_irq_restore(flags);
> }
>
> +static u8 __init get_vtl(void)
> +{
> + u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS;
> + struct hv_get_vp_registers_input *input;
> + struct hv_get_vp_registers_output *output;
> + u64 vtl = 0;
> + u64 ret;
> + unsigned long flags;
> +
> + local_irq_save(flags);
> + input = *this_cpu_ptr(hyperv_pcpu_input_arg);
> + output = (struct hv_get_vp_registers_output *)input;
> + if (!input) {
> + local_irq_restore(flags);
> + goto done;
> + }
> +
> + memset(input, 0, struct_size(input, element, 1));
> + input->header.partitionid = HV_PARTITION_ID_SELF;
> + input->header.vpindex = HV_VP_INDEX_SELF;
> + input->header.inputvtl = 0;
> + input->element[0].name0 = HV_X64_REGISTER_VSM_VP_STATUS;
> +
> + ret = hv_do_hypercall(control, input, output);
> + if (hv_result_success(ret))
> + vtl = output->as64.low & HV_X64_VTL_MASK;
> + else
> + pr_err("Hyper-V: failed to get VTL! %lld", ret);
> + local_irq_restore(flags);
> +
> +done:
> + return vtl;
> +}
> +
> /*
> * This function is to be invoked early in the boot sequence after the
> * hypervisor has been detected.
> @@ -506,6 +540,8 @@ void __init hyperv_init(void)
> /* Query the VMs extended capability once, so that it can be cached. */
> hv_query_ext_cap(0);
>
> + /* Find the VTL */
> + ms_hyperv.vtl = get_vtl();
> return;
>
> clean_guest_os_id:
> diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h
> index cea95dcd27c2..4bf0b315b0ce 100644
> --- a/arch/x86/include/asm/hyperv-tlfs.h
> +++ b/arch/x86/include/asm/hyperv-tlfs.h
> @@ -301,6 +301,13 @@ enum hv_isolation_type {
> #define HV_X64_MSR_TIME_REF_COUNT HV_REGISTER_TIME_REF_COUNT
> #define HV_X64_MSR_REFERENCE_TSC HV_REGISTER_REFERENCE_TSC
>
> +/*
> + * Registers are only accessible via HVCALL_GET_VP_REGISTERS hvcall and
> + * there is not associated MSR address.
> + */
> +#define HV_X64_REGISTER_VSM_VP_STATUS 0x000D0003
> +#define HV_X64_VTL_MASK GENMASK(3, 0)
> +
> /* Hyper-V memory host visibility */
> enum hv_mem_host_visibility {
> VMBUS_PAGE_NOT_VISIBLE = 0,
> diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
> index 5978e9dbc286..02b54f85dc60 100644
> --- a/drivers/hv/connection.c
> +++ b/drivers/hv/connection.c
> @@ -98,6 +98,7 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo
> *msginfo, u32 version)
> */
> if (version >= VERSION_WIN10_V5) {
> msg->msg_sint = VMBUS_MESSAGE_SINT;
> + msg->msg_vtl = ms_hyperv.vtl;
> vmbus_connection.msg_conn_id =
> VMBUS_MESSAGE_CONNECTION_ID_4;
> } else {
> msg->interrupt_page = virt_to_phys(vmbus_connection.int_page);
> diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
> index 6b5c41f90398..f73a044ecaa7 100644
> --- a/include/asm-generic/mshyperv.h
> +++ b/include/asm-generic/mshyperv.h
> @@ -54,6 +54,7 @@ struct ms_hyperv_info {
> };
> };
> u64 shared_gpa_boundary;
> + u8 vtl;
> };
> extern struct ms_hyperv_info ms_hyperv;
> extern bool hv_nested;
> diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
> index bfbc37ce223b..1f2bfec4abde 100644
> --- a/include/linux/hyperv.h
> +++ b/include/linux/hyperv.h
> @@ -665,8 +665,8 @@ struct vmbus_channel_initiate_contact {
> u64 interrupt_page;
> struct {
> u8 msg_sint;
> - u8 padding1[3];
> - u32 padding2;
> + u8 msg_vtl;
> + u8 reserved[6];
> };
> };
> u64 monitor_page1;
> --
> 2.25.1
^ permalink raw reply
* RE: [PATCH V2 1/9] x86/hyperv: Add sev-snp enlightened guest static key
From: Michael Kelley (LINUX) @ 2023-07-04 14:17 UTC (permalink / raw)
To: Tianyu Lan, KY Srinivasan, Haiyang Zhang, wei.liu@kernel.org,
Dexuan Cui, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
daniel.lezcano@linaro.org, arnd@arndb.de
Cc: Tianyu Lan, linux-arch@vger.kernel.org,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
vkuznets@redhat.com
In-Reply-To: <20230627032248.2170007-2-ltykernel@gmail.com>
From: Tianyu Lan <ltykernel@gmail.com> Sent: Monday, June 26, 2023 8:23 PM
>
> Introduce static key isolation_type_en_snp for enlightened
> sev-snp guest check.
>
> Signed-off-by: Tianyu Lan <tiala@microsoft.com>
> ---
> arch/x86/hyperv/ivm.c | 11 +++++++++++
> arch/x86/include/asm/mshyperv.h | 3 +++
> arch/x86/kernel/cpu/mshyperv.c | 9 +++++++--
> drivers/hv/hv_common.c | 6 ++++++
> include/asm-generic/mshyperv.h | 12 +++++++++---
> 5 files changed, 36 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
> index cc92388b7a99..5d3ee3124e00 100644
> --- a/arch/x86/hyperv/ivm.c
> +++ b/arch/x86/hyperv/ivm.c
> @@ -409,3 +409,14 @@ bool hv_isolation_type_snp(void)
> {
> return static_branch_unlikely(&isolation_type_snp);
> }
> +
> +DEFINE_STATIC_KEY_FALSE(isolation_type_en_snp);
> +/*
> + * hv_isolation_type_en_snp - Check system runs in the AMD SEV-SNP based
> + * isolation enlightened VM.
> + */
> +bool hv_isolation_type_en_snp(void)
> +{
> + return static_branch_unlikely(&isolation_type_en_snp);
> +}
> +
Vitaly had suggested some renaming of this and related variables and
functions, which you had agreed to do. But I don't see that renaming
reflected in this patch or throughout the full patch set.
Michael
> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
> index 49bb4f2bd300..31c476f4e656 100644
> --- a/arch/x86/include/asm/mshyperv.h
> +++ b/arch/x86/include/asm/mshyperv.h
> @@ -26,6 +26,7 @@
> union hv_ghcb;
>
> DECLARE_STATIC_KEY_FALSE(isolation_type_snp);
> +DECLARE_STATIC_KEY_FALSE(isolation_type_en_snp);
>
> typedef int (*hyperv_fill_flush_list_func)(
> struct hv_guest_mapping_flush_list *flush,
> @@ -45,6 +46,8 @@ extern void *hv_hypercall_pg;
>
> extern u64 hv_current_partition_id;
>
> +extern bool hv_isolation_type_en_snp(void);
> +
> extern union hv_ghcb * __percpu *hv_ghcb_pg;
>
> int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index c7969e806c64..5398fb2f4d39 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -402,8 +402,12 @@ static void __init ms_hyperv_init_platform(void)
> pr_info("Hyper-V: Isolation Config: Group A 0x%x, Group B 0x%x\n",
> ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b);
>
> - if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP)
> +
> + if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) {
> + static_branch_enable(&isolation_type_en_snp);
> + } else if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) {
> static_branch_enable(&isolation_type_snp);
> + }
> }
>
> if (hv_max_functions_eax >= HYPERV_CPUID_NESTED_FEATURES) {
> @@ -473,7 +477,8 @@ static void __init ms_hyperv_init_platform(void)
>
> #if IS_ENABLED(CONFIG_HYPERV)
> if ((hv_get_isolation_type() == HV_ISOLATION_TYPE_VBS) ||
> - (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP))
> + ((hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) &&
> + ms_hyperv.paravisor_present))
> hv_vtom_init();
> /*
> * Setup the hook to get control post apic initialization.
> diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> index 542a1d53b303..4b4aa53c34c2 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -502,6 +502,12 @@ bool __weak hv_isolation_type_snp(void)
> }
> EXPORT_SYMBOL_GPL(hv_isolation_type_snp);
>
> +bool __weak hv_isolation_type_en_snp(void)
> +{
> + return false;
> +}
> +EXPORT_SYMBOL_GPL(hv_isolation_type_en_snp);
> +
> void __weak hv_setup_vmbus_handler(void (*handler)(void))
> {
> }
> diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
> index 402a8c1c202d..6b5c41f90398 100644
> --- a/include/asm-generic/mshyperv.h
> +++ b/include/asm-generic/mshyperv.h
> @@ -36,15 +36,21 @@ struct ms_hyperv_info {
> u32 nested_features;
> u32 max_vp_index;
> u32 max_lp_index;
> - u32 isolation_config_a;
> + union {
> + u32 isolation_config_a;
> + struct {
> + u32 paravisor_present : 1;
> + u32 reserved_a1 : 31;
> + };
> + };
> union {
> u32 isolation_config_b;
> struct {
> u32 cvm_type : 4;
> - u32 reserved1 : 1;
> + u32 reserved_b1 : 1;
> u32 shared_gpa_boundary_active : 1;
> u32 shared_gpa_boundary_bits : 6;
> - u32 reserved2 : 20;
> + u32 reserved_b2 : 20;
> };
> };
> u64 shared_gpa_boundary;
> --
> 2.25.1
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox