linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Rothwell <sfr@canb.auug.org.au>
To: Wei Liu <wei.liu@kernel.org>
Cc: Dexuan Cui <decui@microsoft.com>,
	Lillian Grassin-Drake <ligrassi@microsoft.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux Next Mailing List <linux-next@vger.kernel.org>,
	Sunil Muthuswamy <sunilmut@microsoft.com>
Subject: linux-next: manual merge of the hyperv tree with Linus' tree
Date: Fri, 5 Feb 2021 19:02:02 +1100	[thread overview]
Message-ID: <20210205190202.29c2b74e@canb.auug.org.au> (raw)

[-- Attachment #1: Type: text/plain, Size: 5318 bytes --]

Hi all,

Today's linux-next merge of the hyperv tree got a conflict in:

  arch/x86/hyperv/hv_init.c

between commit:

  fff7b5e6ee63 ("x86/hyperv: Initialize clockevents after LAPIC is initialized")

from Linus' tree and commits:

  a06c2e7df586 ("x86/hyperv: extract partition ID from Microsoft Hypervisor if necessary")
  fa2c411b58fe ("x86/hyperv: implement an MSI domain for root partition")

from the hyperv tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc arch/x86/hyperv/hv_init.c
index 6375967a8244,5ad48e8033e3..000000000000
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@@ -26,9 -26,11 +27,13 @@@
  #include <linux/cpuhotplug.h>
  #include <linux/syscore_ops.h>
  #include <clocksource/hyperv_timer.h>
+ #include <linux/highmem.h>
+ 
+ u64 hv_current_partition_id = ~0ull;
+ EXPORT_SYMBOL_GPL(hv_current_partition_id);
  
 +int hyperv_init_cpuhp;
 +
  void *hv_hypercall_pg;
  EXPORT_SYMBOL_GPL(hv_hypercall_pg);
  
@@@ -315,25 -339,24 +342,43 @@@ static struct syscore_ops hv_syscore_op
  	.resume		= hv_resume,
  };
  
 +static void (* __initdata old_setup_percpu_clockev)(void);
 +
 +static void __init hv_stimer_setup_percpu_clockev(void)
 +{
 +	/*
 +	 * Ignore any errors in setting up stimer clockevents
 +	 * as we can run with the LAPIC timer as a fallback.
 +	 */
 +	(void)hv_stimer_alloc();
 +
 +	/*
 +	 * Still register the LAPIC timer, because the direct-mode STIMER is
 +	 * not supported by old versions of Hyper-V. This also allows users
 +	 * to switch to LAPIC timer via /sys, if they want to.
 +	 */
 +	if (old_setup_percpu_clockev)
 +		old_setup_percpu_clockev();
 +}
 +
+ static void __init hv_get_partition_id(void)
+ {
+ 	struct hv_get_partition_id *output_page;
+ 	u64 status;
+ 	unsigned long flags;
+ 
+ 	local_irq_save(flags);
+ 	output_page = *this_cpu_ptr(hyperv_pcpu_output_arg);
+ 	status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output_page);
+ 	if ((status & HV_HYPERCALL_RESULT_MASK) != HV_STATUS_SUCCESS) {
+ 		/* No point in proceeding if this failed */
+ 		pr_err("Failed to get partition ID: %lld\n", status);
+ 		BUG();
+ 	}
+ 	hv_current_partition_id = output_page->partition_id;
+ 	local_irq_restore(flags);
+ }
+ 
  /*
   * This function is to be invoked early in the boot sequence after the
   * hypervisor has been detected.
@@@ -408,18 -437,41 +459,45 @@@ void __init hyperv_init(void
  
  	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
  	hypercall_msr.enable = 1;
- 	hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg);
- 	wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+ 
+ 	if (hv_root_partition) {
+ 		struct page *pg;
+ 		void *src, *dst;
+ 
+ 		/*
+ 		 * For the root partition, the hypervisor will set up its
+ 		 * hypercall page. The hypervisor guarantees it will not show
+ 		 * up in the root's address space. The root can't change the
+ 		 * location of the hypercall page.
+ 		 *
+ 		 * Order is important here. We must enable the hypercall page
+ 		 * so it is populated with code, then copy the code to an
+ 		 * executable page.
+ 		 */
+ 		wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+ 
+ 		pg = vmalloc_to_page(hv_hypercall_pg);
+ 		dst = kmap(pg);
+ 		src = memremap(hypercall_msr.guest_physical_address << PAGE_SHIFT, PAGE_SIZE,
+ 				MEMREMAP_WB);
+ 		BUG_ON(!(src && dst));
+ 		memcpy(dst, src, HV_HYP_PAGE_SIZE);
+ 		memunmap(src);
+ 		kunmap(pg);
+ 	} else {
+ 		hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg);
+ 		wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
+ 	}
  
  	/*
 -	 * Ignore any errors in setting up stimer clockevents
 -	 * as we can run with the LAPIC timer as a fallback.
 +	 * hyperv_init() is called before LAPIC is initialized: see
 +	 * apic_intr_mode_init() -> x86_platform.apic_post_init() and
 +	 * apic_bsp_setup() -> setup_local_APIC(). The direct-mode STIMER
 +	 * depends on LAPIC, so hv_stimer_alloc() should be called from
 +	 * x86_init.timers.setup_percpu_clockev.
  	 */
 -	(void)hv_stimer_alloc();
 +	old_setup_percpu_clockev = x86_init.timers.setup_percpu_clockev;
 +	x86_init.timers.setup_percpu_clockev = hv_stimer_setup_percpu_clockev;
  
  	hv_apic_init();
  
@@@ -427,7 -479,20 +505,22 @@@
  
  	register_syscore_ops(&hv_syscore_ops);
  
 +	hyperv_init_cpuhp = cpuhp;
++
+ 	if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_ACCESS_PARTITION_ID)
+ 		hv_get_partition_id();
+ 
+ 	BUG_ON(hv_root_partition && hv_current_partition_id == ~0ull);
+ 
+ #ifdef CONFIG_PCI_MSI
+ 	/*
+ 	 * If we're running as root, we want to create our own PCI MSI domain.
+ 	 * We can't set this in hv_pci_init because that would be too late.
+ 	 */
+ 	if (hv_root_partition)
+ 		x86_init.irqs.create_pci_msi_domain = hv_create_pci_msi_domain;
+ #endif
+ 
  	return;
  
  remove_cpuhp_state:

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

             reply	other threads:[~2021-02-05  8:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05  8:02 Stephen Rothwell [this message]
2021-02-05 10:13 ` linux-next: manual merge of the hyperv tree with Linus' tree Wei Liu
  -- strict thread matches above, loose matches on Subject: below --
2021-05-12  3:19 Stephen Rothwell
2019-07-09  9:53 Stephen Rothwell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210205190202.29c2b74e@canb.auug.org.au \
    --to=sfr@canb.auug.org.au \
    --cc=decui@microsoft.com \
    --cc=ligrassi@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=sunilmut@microsoft.com \
    --cc=wei.liu@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).