From: Mao Minkai maominkai@wxiat.com
Sunway inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I56OLG
--------------------------------
Rename variables for kvm_mem cmdline to improve readability.
Signed-off-by: Mao Minkai maominkai@wxiat.com
Signed-off-by: Gu Zitao guzitao@wxiat.com --- arch/sw_64/kernel/setup.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/arch/sw_64/kernel/setup.c b/arch/sw_64/kernel/setup.c index e5abef2dc593..26a611448ad6 100644 --- a/arch/sw_64/kernel/setup.c +++ b/arch/sw_64/kernel/setup.c @@ -81,8 +81,8 @@ DEFINE_PER_CPU(unsigned long, hard_node_id) = { 0 }; struct cma *sw64_kvm_cma; EXPORT_SYMBOL(sw64_kvm_cma);
-static phys_addr_t size_cmdline; -static phys_addr_t base_cmdline; +static phys_addr_t kvm_mem_size; +static phys_addr_t kvm_mem_base;
struct gen_pool *sw64_kvm_pool; EXPORT_SYMBOL(sw64_kvm_pool); @@ -748,17 +748,17 @@ static int __init early_kvm_reserved_mem(char *p) return -EINVAL; }
- size_cmdline = memparse(p, &p); + kvm_mem_size = memparse(p, &p); if (*p != '@') return -EINVAL; - base_cmdline = memparse(p + 1, &p); + kvm_mem_base = memparse(p + 1, &p); return 0; } early_param("kvm_mem", early_kvm_reserved_mem);
void __init sw64_kvm_reserve(void) { - kvm_cma_declare_contiguous(base_cmdline, size_cmdline, 0, + kvm_cma_declare_contiguous(kvm_mem_base, kvm_mem_size, 0, PAGE_SIZE, 0, "sw64_kvm_cma", &sw64_kvm_cma); } #endif @@ -1030,14 +1030,14 @@ static int __init sw64_kvm_pool_init(void) if (!sw64_kvm_cma) goto out;
- kvm_pool_virt = (unsigned long)base_cmdline; + kvm_pool_virt = (unsigned long)kvm_mem_base;
sw64_kvm_pool = gen_pool_create(PAGE_SHIFT, -1); if (!sw64_kvm_pool) goto out;
- status = gen_pool_add_virt(sw64_kvm_pool, kvm_pool_virt, base_cmdline, - size_cmdline, -1); + status = gen_pool_add_virt(sw64_kvm_pool, kvm_pool_virt, kvm_mem_base, + kvm_mem_size, -1); if (status < 0) { pr_err("failed to add memory chunks to sw64 kvm pool\n"); gen_pool_destroy(sw64_kvm_pool); @@ -1046,8 +1046,8 @@ static int __init sw64_kvm_pool_init(void) } gen_pool_set_algo(sw64_kvm_pool, gen_pool_best_fit, NULL);
- base_page = pfn_to_page(base_cmdline >> PAGE_SHIFT); - end_page = pfn_to_page((base_cmdline + size_cmdline) >> PAGE_SHIFT); + base_page = pfn_to_page(kvm_mem_base >> PAGE_SHIFT); + end_page = pfn_to_page((kvm_mem_base + kvm_mem_size) >> PAGE_SHIFT);
p = base_page; while (page_ref_count(p) == 0 &&
From: Zheng Chongzhen zhengchongzhen@wxiat.com
Sunway inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I56QAM
--------------------------------
It fixes pci_domain_nr redefined error when CONFIG_PCI=n.
Signed-off-by: Zheng Chongzhen zhengchongzhen@wxiat.com
Signed-off-by: Gu Zitao guzitao@wxiat.com --- arch/sw_64/Kconfig | 3 +-- arch/sw_64/include/asm/pci.h | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/sw_64/Kconfig b/arch/sw_64/Kconfig index 318a423d87dd..347958e60023 100644 --- a/arch/sw_64/Kconfig +++ b/arch/sw_64/Kconfig @@ -279,8 +279,7 @@ config PCI VESA. If you have PCI, say Y, otherwise N.
config PCI_DOMAINS - bool - default y + def_bool PCI
config PCI_SYSCALL def_bool PCI diff --git a/arch/sw_64/include/asm/pci.h b/arch/sw_64/include/asm/pci.h index f1c291101811..fc6a4b469f30 100644 --- a/arch/sw_64/include/asm/pci.h +++ b/arch/sw_64/include/asm/pci.h @@ -77,6 +77,7 @@ extern struct pci_controller *hose_head; extern struct syscore_ops iommu_cpu_syscore_ops; #endif
+#ifdef CONFIG_PCI_DOMAINS static inline int pci_domain_nr(struct pci_bus *bus) { return 0; }
static inline int pci_proc_domain(struct pci_bus *bus) @@ -85,6 +86,7 @@ static inline int pci_proc_domain(struct pci_bus *bus)
return hose->need_domain_info; } +#endif
#ifdef CONFIG_NUMA static inline int __pcibus_to_node(const struct pci_bus *bus)
From: Du Yilong duyilong@wxiat.com
Sunway inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I56WV8
--------------------------------
sw_64/kvm map the memory of VM instance to QEMU's user space by remap_pfn_range(), which set the vma flag with VM_IO and VM_PFNMAP.
The previous commit set these pages as reserved and follow_pfn() method will get pfn of a PFNMAP vma correctly to fix bug if user do munmap on the vma.
But in generic_file_read_iter() with O_DIRECT flag will call __get_user_pages() and return -EFAULT because of VM_IO and VM_PFNMAP, then bio_iov_iter_get_pages() failed to get the physical pages corresponding to the user virtual address.
To solve this problem, VM_IO and VM_PFNMAP of the vma flag were cleared and set again before release this vma.
Signed-off-by: Du Yilong duyilong@wxiat.com
Signed-off-by: Gu Zitao guzitao@wxiat.com --- arch/sw_64/include/asm/mmu_context.h | 8 ++++++++ arch/sw_64/kernel/setup.c | 1 - arch/sw_64/kvm/kvm-sw64.c | 9 ++++++--- 3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/arch/sw_64/include/asm/mmu_context.h b/arch/sw_64/include/asm/mmu_context.h index e3d7ae7c873e..4866ea6d81bb 100644 --- a/arch/sw_64/include/asm/mmu_context.h +++ b/arch/sw_64/include/asm/mmu_context.h @@ -195,6 +195,14 @@ static inline int arch_dup_mmap(struct mm_struct *oldmm,
static inline void arch_exit_mmap(struct mm_struct *mm) { + struct vm_area_struct *vma; + + vma = mm->mmap; + while (vma) { + if (vma->vm_flags & VM_ARCH_1) + vma->vm_flags |= VM_IO | VM_PFNMAP; + vma = vma->vm_next; + } }
static inline void arch_unmap(struct mm_struct *mm, unsigned long start, diff --git a/arch/sw_64/kernel/setup.c b/arch/sw_64/kernel/setup.c index 26a611448ad6..e081483194e6 100644 --- a/arch/sw_64/kernel/setup.c +++ b/arch/sw_64/kernel/setup.c @@ -1053,7 +1053,6 @@ static int __init sw64_kvm_pool_init(void) while (page_ref_count(p) == 0 && (unsigned long)p <= (unsigned long)end_page) { set_page_count(p, 1); - SetPageReserved(p); p++; }
diff --git a/arch/sw_64/kvm/kvm-sw64.c b/arch/sw_64/kvm/kvm-sw64.c index e1f7a82fbc26..4e7933fd80ed 100644 --- a/arch/sw_64/kvm/kvm-sw64.c +++ b/arch/sw_64/kvm/kvm-sw64.c @@ -297,6 +297,9 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, ret = vm_mmap(vm_file, mem->userspace_addr, mem->memory_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, 0); + if ((long)ret < 0) + return ret; + vma = find_vma(current->mm, mem->userspace_addr); if (!vma) return -ENOMEM; @@ -311,14 +314,14 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, remap_pfn_range(vma, mem->userspace_addr, addr >> PAGE_SHIFT, mem->memory_size, vma->vm_page_prot); - - if ((long)ret < 0) - return ret; } else { info = vm_file->private_data; addr = info->start; }
+ vma->vm_flags &= ~(VM_IO | VM_PFNMAP); + vma->vm_flags |= VM_ARCH_1; + pr_info("guest phys addr = %#lx, size = %#lx\n", addr, vma->vm_end - vma->vm_start); kvm->arch.mem.membank[0].guest_phys_addr = 0;
From: He Sheng hesheng@wxiat.com
Sunway inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I56U83
--------------------------------
sw64 fits all conditions required by the generic get_user_pages_fast() code, so activate this feature by default.
Signed-off-by: He Sheng hesheng@wxiat.com
Signed-off-by: Gu Zitao guzitao@wxiat.com --- arch/sw_64/Kconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/arch/sw_64/Kconfig b/arch/sw_64/Kconfig index 347958e60023..6c9fb51347f3 100644 --- a/arch/sw_64/Kconfig +++ b/arch/sw_64/Kconfig @@ -12,6 +12,7 @@ config SW64 select HAVE_PCSPKR_PLATFORM select HAVE_PERF_EVENTS select HAVE_GENERIC_HARDIRQS + select HAVE_GENERIC_GUP select GENERIC_CLOCKEVENTS select GENERIC_IRQ_PROBE select GENERIC_IRQ_LEGACY
From: He Sheng hesheng@wxiat.com
Sunway inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I56OLG
--------------------------------
It does not support a.out and ECOFF binaries on sw64, so a.out.h can be removed.
Signed-off-by: He Sheng hesheng@wxiat.com
Signed-off-by: Gu Zitao guzitao@wxiat.com --- arch/sw_64/include/asm/a.out.h | 16 ------ arch/sw_64/include/uapi/asm/a.out.h | 88 ----------------------------- 2 files changed, 104 deletions(-) delete mode 100644 arch/sw_64/include/asm/a.out.h delete mode 100644 arch/sw_64/include/uapi/asm/a.out.h
diff --git a/arch/sw_64/include/asm/a.out.h b/arch/sw_64/include/asm/a.out.h deleted file mode 100644 index 4f2004a7fa8e..000000000000 --- a/arch/sw_64/include/asm/a.out.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _ASM_SW64_A_OUT_H -#define _ASM_SW64_A_OUT_H - -#include <uapi/asm/a.out.h> - -/* Assume that start addresses below 4G belong to a TASO application. - * Unfortunately, there is no proper bit in the exec header to check. - * Worse, we have to notice the start address before swapping to use - * /sbin/loader, which of course is _not_ a TASO application. - */ -#define SET_AOUT_PERSONALITY(BFPM, EX) \ - set_personality(((BFPM->taso || EX.ah.entry < 0x100000000L \ - ? ADDR_LIMIT_32BIT : 0) | PER_OSF4)) - -#endif /* _ASM_SW64_A_OUT_H */ diff --git a/arch/sw_64/include/uapi/asm/a.out.h b/arch/sw_64/include/uapi/asm/a.out.h deleted file mode 100644 index addb648b8ed6..000000000000 --- a/arch/sw_64/include/uapi/asm/a.out.h +++ /dev/null @@ -1,88 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _UAPI_ASM_SW64_A_OUT_H -#define _UAPI_ASM_SW64_A_OUT_H - -#include <linux/types.h> - -/* - * ECOFF header structs. ECOFF files consist of: - * - a file header (struct filehdr), - * - an a.out header (struct aouthdr), - * - one or more section headers (struct scnhdr). - * The filhdr's "f_nscns" field contains the - * number of section headers. - */ - -struct filehdr { - /* "file" header */ - __u16 f_magic, f_nscns; - __u32 f_timdat; - __u64 f_symptr; - __u32 f_nsyms; - __u16 f_opthdr, f_flags; -}; - -struct aouthdr { - __u64 info; /* after that it looks quite normal.. */ - __u64 tsize; - __u64 dsize; - __u64 bsize; - __u64 entry; - __u64 text_start; /* with a few additions that actually make sense */ - __u64 data_start; - __u64 bss_start; - __u32 gprmask, fprmask; /* bitmask of general & floating point regs used in binary */ - __u64 gpvalue; -}; - -struct scnhdr { - char s_name[8]; - __u64 s_paddr; - __u64 s_vaddr; - __u64 s_size; - __u64 s_scnptr; - __u64 s_relptr; - __u64 s_lnnoptr; - __u16 s_nreloc; - __u16 s_nlnno; - __u32 s_flags; -}; - -struct exec { - /* "file" header */ - struct filehdr fh; - struct aouthdr ah; -}; - -/* - * Define's so that the kernel exec code can access the a.out header - * fields... - */ -#define a_info ah.info -#define a_text ah.tsize -#define a_data ah.dsize -#define a_bss ah.bsize -#define a_entry ah.entry -#define a_textstart ah.text_start -#define a_datastart ah.data_start -#define a_bssstart ah.bss_start -#define a_gprmask ah.gprmask -#define a_fprmask ah.fprmask -#define a_gpvalue ah.gpvalue - -#define N_TXTADDR(x) ((x).a_textstart) -#define N_DATADDR(x) ((x).a_datastart) -#define N_BSSADDR(x) ((x).a_bssstart) -#define N_DRSIZE(x) 0 -#define N_TRSIZE(x) 0 -#define N_SYMSIZE(x) 0 - -#define AOUTHSZ sizeof(struct aouthdr) -#define SCNHSZ sizeof(struct scnhdr) -#define SCNROUND 16 - -#define N_TXTOFF(x) \ - ((long) N_MAGIC(x) == ZMAGIC ? 0 : \ - (sizeof(struct exec) + (x).fh.f_nscns * SCNHSZ + SCNROUND - 1) & ~(SCNROUND - 1)) - -#endif /* _UAPI_ASM_SW64_A_OUT_H */
From: Lu Feifei lufeifei@wxiat.com
Sunway inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I56WV8
--------------------------------
Output kernel log through the specified IO address is required by qemu, and this method is not required by guest.
Signed-off-by: Lu Feifei lufeifei@wxiat.com
Signed-off-by: Gu Zitao guzitao@wxiat.com --- arch/sw_64/include/asm/hw_init.h | 1 + arch/sw_64/kernel/dup_print.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/sw_64/include/asm/hw_init.h b/arch/sw_64/include/asm/hw_init.h index ede8da6b0314..594704756e72 100644 --- a/arch/sw_64/include/asm/hw_init.h +++ b/arch/sw_64/include/asm/hw_init.h @@ -106,6 +106,7 @@ DECLARE_STATIC_KEY_FALSE(run_mode_emul_key);
#define is_in_host() static_branch_likely(&run_mode_host_key) #define is_in_guest() static_branch_unlikely(&run_mode_guest_key) +#define is_in_emul() static_branch_unlikely(&run_mode_emul_key) #define is_guest_or_emul() !static_branch_likely(&run_mode_host_key)
#define CPU_SW3231 0x31 diff --git a/arch/sw_64/kernel/dup_print.c b/arch/sw_64/kernel/dup_print.c index fae543625f62..e1c05cfa864b 100644 --- a/arch/sw_64/kernel/dup_print.c +++ b/arch/sw_64/kernel/dup_print.c @@ -40,7 +40,7 @@ int sw64_printk(const char *fmt, va_list args) printed_len += vscnprintf(sw64_printk_buf, 1024, fmt, args); } else { printed_len += vscnprintf(sw64_printk_buf, 1024, fmt, args); - if (is_guest_or_emul()) { + if (is_in_emul()) { unsigned long write_addr = QEMU_PRINTF_BUFF_BASE; *(unsigned long *)write_addr = (unsigned long)((((unsigned long)sw64_printk_buf) & 0xffffffffUL) | ((unsigned long)printed_len << 32));
From: Mao Minkai maominkai@wxiat.com
Sunway inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I56OLG
--------------------------------
Signed-off-by: Mao Minkai maominkai@wxiat.com
Signed-off-by: Gu Zitao guzitao@wxiat.com --- arch/sw_64/kernel/syscalls/syscall.tbl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/arch/sw_64/kernel/syscalls/syscall.tbl b/arch/sw_64/kernel/syscalls/syscall.tbl index 37b1e3f9f9e2..37a46ec99ccf 100644 --- a/arch/sw_64/kernel/syscalls/syscall.tbl +++ b/arch/sw_64/kernel/syscalls/syscall.tbl @@ -290,11 +290,11 @@ 280 common fspick sys_fspick 281 common pidfd_open sys_pidfd_open 282 common clone3 sys_clone3 -283 common close_range sys_close_range -284 common openat2 sys_openat2 -285 common pidfd_getfd sys_pidfd_getfd -286 common faccessat2 sys_faccessat2 -287 common process_madvise sys_process_madvise +283 common close_range sys_close_range +284 common openat2 sys_openat2 +285 common pidfd_getfd sys_pidfd_getfd +286 common faccessat2 sys_faccessat2 +287 common process_madvise sys_process_madvise #288 is unused #289 is unused #290 is unused
From: Mao Minkai maominkai@wxiat.com
Sunway inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I56U83
--------------------------------
Most architectures define system call numbers for the pkey system calls even when they don't support the features, and perhaps never will. sw64 miss these before, so just define them anyway for consistency.
Signed-off-by: Mao Minkai maominkai@wxiat.com
Signed-off-by: Gu Zitao guzitao@wxiat.com --- arch/sw_64/include/uapi/asm/unistd.h | 5 ----- arch/sw_64/kernel/syscalls/syscall.tbl | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/arch/sw_64/include/uapi/asm/unistd.h b/arch/sw_64/include/uapi/asm/unistd.h index 225358536dc9..c4fdde96c640 100644 --- a/arch/sw_64/include/uapi/asm/unistd.h +++ b/arch/sw_64/include/uapi/asm/unistd.h @@ -9,9 +9,4 @@
#include <asm/unistd_64.h>
-/* sw64 doesn't have protection keys. */ -#define __IGNORE_pkey_mprotect -#define __IGNORE_pkey_alloc -#define __IGNORE_pkey_free - #endif /* _UAPI_ASM_SW64_UNISTD_H */ diff --git a/arch/sw_64/kernel/syscalls/syscall.tbl b/arch/sw_64/kernel/syscalls/syscall.tbl index 37a46ec99ccf..6026c637d923 100644 --- a/arch/sw_64/kernel/syscalls/syscall.tbl +++ b/arch/sw_64/kernel/syscalls/syscall.tbl @@ -295,9 +295,9 @@ 285 common pidfd_getfd sys_pidfd_getfd 286 common faccessat2 sys_faccessat2 287 common process_madvise sys_process_madvise -#288 is unused -#289 is unused -#290 is unused +288 common pkey_mprotect sys_pkey_mprotect +289 common pkey_alloc sys_pkey_alloc +290 common pkey_free sys_pkey_free #291 is unused #292 is unused #293 is unused
From: Mao Minkai maominkai@wxiat.com
Sunway inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I56XYC
--------------------------------
The implementation of clone3 on sw64 is a bit different from the generic one.
Signed-off-by: Mao Minkai maominkai@wxiat.com
Signed-off-by: Gu Zitao guzitao@wxiat.com --- arch/sw_64/include/asm/unistd.h | 1 + arch/sw_64/kernel/entry.S | 1 + arch/sw_64/kernel/syscalls/syscall.tbl | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/sw_64/include/asm/unistd.h b/arch/sw_64/include/asm/unistd.h index c1778adf4fba..b8854163d96f 100644 --- a/arch/sw_64/include/asm/unistd.h +++ b/arch/sw_64/include/asm/unistd.h @@ -22,5 +22,6 @@ #define __ARCH_WANT_SYS_CLONE #define __ARCH_WANT_SYS_SOCKETCALL #define __ARCH_WANT_SYS_SIGPROCMASK +#define __ARCH_WANT_SYS_CLONE3
#endif /* _ASM_SW64_UNISTD_H */ diff --git a/arch/sw_64/kernel/entry.S b/arch/sw_64/kernel/entry.S index 753eb31a76c6..c12487e52141 100644 --- a/arch/sw_64/kernel/entry.S +++ b/arch/sw_64/kernel/entry.S @@ -659,6 +659,7 @@ sw64_\name: fork_like fork fork_like vfork fork_like clone +fork_like clone3
.align 4 .globl sys_sigreturn diff --git a/arch/sw_64/kernel/syscalls/syscall.tbl b/arch/sw_64/kernel/syscalls/syscall.tbl index 6026c637d923..472957792bd2 100644 --- a/arch/sw_64/kernel/syscalls/syscall.tbl +++ b/arch/sw_64/kernel/syscalls/syscall.tbl @@ -289,7 +289,7 @@ 279 common fsmount sys_fsmount 280 common fspick sys_fspick 281 common pidfd_open sys_pidfd_open -282 common clone3 sys_clone3 +282 common clone3 sw64_clone3 283 common close_range sys_close_range 284 common openat2 sys_openat2 285 common pidfd_getfd sys_pidfd_getfd
Sunway inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I56P0Z
--------------------------------
We were relying on GNU nm's ability to extract our VDSO symbols, but newer nm will always display version strings after symbol names, which cause so2s.sh to fail to generate vdso-syms.S. Fix so2s.sh to make it work.
Besides, remove the copyright strings from so2s.sh.
Signed-off-by: Gu Zitao guzitao@wxiat.com
Signed-off-by: Gu Zitao guzitao@wxiat.com --- arch/sw_64/kernel/vdso/so2s.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/sw_64/kernel/vdso/so2s.sh b/arch/sw_64/kernel/vdso/so2s.sh index 8f23ac544d1b..e1763af8e730 100755 --- a/arch/sw_64/kernel/vdso/so2s.sh +++ b/arch/sw_64/kernel/vdso/so2s.sh @@ -1,5 +1,4 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0+ -# Copyright 2020 Palmer Dabbelt palmerdabbelt@google.com
-grep -v "LINUX" | sed 's/([0-9a-f]*) T ([a-z0-9_]*)/.globl\t\2\n\2:\n.quad\t0x\1/' +grep "__vdso_" | sed 's/([0-9a-f]*) T ([a-z0-9_]*)(@@LINUX_.*)*/.globl\t\2\n\2:\n.quad\t0x\1/'