From patchwork Wed Sep 13 00:23:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 9950375 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EDD0D60360 for ; Wed, 13 Sep 2017 00:26:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEDE328EB3 for ; Wed, 13 Sep 2017 00:26:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D339D28FCF; Wed, 13 Sep 2017 00:26:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4FEFA28EB3 for ; Wed, 13 Sep 2017 00:25:59 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drvSU-0002kP-L5; Wed, 13 Sep 2017 00:23:14 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drvST-0002kH-BC for xen-devel@lists.xenproject.org; Wed, 13 Sep 2017 00:23:13 +0000 Received: from [85.158.139.211] by server-10.bemta-5.messagelabs.com id 7C/43-00743-07A78B95; Wed, 13 Sep 2017 00:23:12 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpnleJIrShJLcpLzFFi42K5GHrjsG5+1Y5 Ig68XNSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxfPzrYCtbrVfRO6WBtYNys3sXIxSEkMJ1R 4uH12SwgDovAMlaJ/WfvsYI4EgKHWCVeTGwBynACOXESTx5eZoSw0yTO3b3HBmFXS3zaOxesR khASWLL5MeMEGMPMUlcOTkHrEhYQE9i8rfbYM0sAqoSx44tBYuzCehLPF17jRnEFhFQluj99R vsDGaBX4wS07u3MYM4wgINjBJPnjSwglTxClhK/O/byw6xYi6jxIFNu1ggEoISJ2c+AbOZBbQ kbvx7ydTFyAFkS0ss/8cBEuYUsJeYdfcO2DZRoG3z9q1im8AoOgtJ9ywk3bMQuhcwMq9iVC9O LSpLLdI11ksqykzPKMlNzMzRNTQw1ctNLS5OTE/NSUwq1kvOz93ECIwOBiDYwbj3n9MhRkkOJ iVR3mzFHZFCfEn5KZUZicUZ8UWlOanFhxhlODiUJHijKoFygkWp6akVaZk5wDiFSUtw8CiJ8N aCpHmLCxJzizPTIVKnGI05Lty59IeJ48CeW3+YhFjy8vNSpcR59UBKBUBKM0rz4AbB0sclRlk pYV5GoNOEeApSi3IzS1DlXzGKczAqCfO2gkzhycwrgdv3CugUJqBTeC5tATmlJBEhJdXAuNVP UueVa9Mqbt5tv7q36Ed8XHv0LMeU9Uv9/l6/3yMTffaPzk//qxu3W70Tc5lc3rD96y0ZaU5zw ddLOCJcPefzP/3uz1i5tOtm4FHjtVL3719e2GRa/ebSjJfsz6qawk975TYcLVV4xvfqzplAny 4BecGCC84vq3olljG8Ccyz81zu8CfWUYmlOCPRUIu5qDgRAHeZX0saAwAA X-Env-Sender: ketuzsezr@gmail.com X-Msg-Ref: server-14.tower-206.messagelabs.com!1505262190!72418370!1 X-Originating-IP: [209.85.216.195] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26854 invoked from network); 13 Sep 2017 00:23:11 -0000 Received: from mail-qt0-f195.google.com (HELO mail-qt0-f195.google.com) (209.85.216.195) by server-14.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 13 Sep 2017 00:23:11 -0000 Received: by mail-qt0-f195.google.com with SMTP id b1so5938716qtc.0 for ; Tue, 12 Sep 2017 17:23:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=nNOaHxO1nCmFcwzxb6Str52KHsW4iPo4tgCqjj5aq9E=; b=bNB3LBnXrCtz4FiIqT81Y345IQaZAQsbqvvJt0DEiB/5e9bkPXVY+E8l35XrGdhxgJ OkdhebCS9qE1enAAAxXA1sVS0c3MAc4UxrXH9+XJPPA4OrcWxc71LtuhUZQGxhYRU4fz 8idEsr4l5j9mvJHUwVDguBno8h7GTy43AVCD3JCQd38pNUxfv4T/wJE6bSLhVzmbjPUK dvoVCdXST/6nOsAnRGiHukJAGjQ5Jg30lc2kBvzAlYHHkImLbeTrPCzX2SEaJNZekmYn 7azOnmV/wEsvbkPoCd0SKwag1nVs7Dyb6LTQHaoGDY7JMle97sScpcZPeIs1mXpTfYJO RRGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=nNOaHxO1nCmFcwzxb6Str52KHsW4iPo4tgCqjj5aq9E=; b=QDIfBox7PuFsmSqbTJjM+Gsx/1Ooiwq5q0A1lpA0TSYqhnf8jNfWUxKaiRXg2Lroai LFAQwk5YgwhViAZONZWhU7j+TXSPfsH0rWzl0AiECvX6YNrRAFEcT3SUq6SsBDJ4TUHT M4M/KZpWT64t4KtZ7PIk9OBdWeSb7F/8vk4asYaT5cvk1V3w6cH9uN20V3JZYLRzXxjK EWO/uIwHiQhmcI+917jeFmw4kv7qxIrs758PY5SY1EKOtrms04n0xG3Xtze4ay2/XtRq YCWPEgHJk7tbhFxtCMfNj5h62bxEco2KluwaIlR+IhysEY4NW4qRhMBlcJ7E2RCIyKKy 9dFg== X-Gm-Message-State: AHPjjUj/aWM+1s7eIbggvKxrGEUID9T452b3UxSSw19a6ar87qaV7gH6 45nwkcLqDxGpvg== X-Google-Smtp-Source: AOwi7QBBjQ85POrLU7M7K/UDXRVSU/cWqPVuzbduE8toCUk243oGPGnSTZYXB858D1cO0DCr8O5W6g== X-Received: by 10.200.47.184 with SMTP id l53mr19044466qta.120.1505262190238; Tue, 12 Sep 2017 17:23:10 -0700 (PDT) Received: from localhost.localdomain (209-6-200-48.s4398.c3-0.smr-ubr2.sbo-smr.ma.cable.rcncustomer.com. [209.6.200.48]) by smtp.gmail.com with ESMTPSA id g132sm8304209qke.11.2017.09.12.17.23.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Sep 2017 17:23:09 -0700 (PDT) Date: Tue, 12 Sep 2017 20:23:07 -0400 From: Konrad Rzeszutek Wilk To: Jan Beulich Message-ID: <20170913002306.GB6632@localhost.localdomain> References: <20170912003726.368-1-konrad.wilk@oracle.com> <20170912003726.368-15-konrad.wilk@oracle.com> <59B8114A020000780017A40A@prv-mh.provo.novell.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <59B8114A020000780017A40A@prv-mh.provo.novell.com> User-Agent: Mutt/1.8.3 (2017-05-23) Cc: sstabellini@kernel.org, andrew.cooper3@citrix.com, Blaise Boscaccy , ross.lagerwall@citrix.com, julien.grall@arm.com, Vegard Nossum , xen-devel@lists.xenproject.org Subject: Re: [Xen-devel] [PATCH v3 14/17] livepatch/x86/arm: arch/x86/mm: generalize do_page_walk() and implement arch_livepatch_lookup_mfn X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Tue, Sep 12, 2017 at 08:54:34AM -0600, Jan Beulich wrote: > >>> On 12.09.17 at 02:37, wrote: > > With this change we can use _do_page_walk() to implement > > arch_livepatch_lookup_mfn() which can be used to find out > > vmap virtual addresses (as under x86 virt_to_mfn won't work > > for vmap, but it does for arm!). > > How about using domain_page_map_to_mfn() instead? It is very colorfull: And then some extra debug: (XEN) ptr=0xffff82004000d000, DIRECTMAP_VIRT_START=0xffff848000000000, VMAP_VIRT_START=0xffff82c000000000, VMAP_VIRT_END=0xffff82d000000000, xen_virt_end=0xffff82d080600000, end=0xffff82d0bfe00000 (XEN) ptr=0xffff820040014000, DIRECTMAP_VIRT_START=0xffff848000000000, VMAP_VIRT_START=0xffff82c000000000, VMAP_VIRT(XEN) (XEN) **************************************** (XEN) Panic on CPU 0: (XEN) Assertion 'va >= MAPCACHE_VIRT_START && va < MAPCACHE_VIRT_END' failed at domain_page.c:358 (XEN) **************************************** (XEN) (XEN) Reboot in five seconds... I will take a look at it later this week, but regardless it will require some tweaking as well. Do you prefer the domain_page_map_to_mfn path in instead of walk_do_page one? > > Jan > diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index 667573c..f90d4c8 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -17,11 +18,18 @@ mfn_t arch_livepatch_lookup_mfn(unsigned long addr) { unsigned long cr3 = read_cr3() >> PAGE_SHIFT; + mfn_t r, r2; + uint64_t mfn; if ( !mfn_valid(_mfn(cr3)) ) return INVALID_MFN; - return _do_page_walk(cr3, addr); + r = _do_page_walk(cr3, addr); + mfn = domain_page_map_to_mfn((void *)addr); + r2 = _mfn(mfn); + WARN_ON( !mfn_eq(r, r2) ); + + return r; } void arch_livepatch_revive(void) .. (XEN) livepatch.c:1450: livepatch: xen_hello_world: CPU1 - IPIing the other 3 CPUs Applying xen_hello_world... (XEN) livepatch: xen_hello_world: Applying 1 functions (XEN) Assertion 'va >= MAPCACHE_VIRT_START && va < MAPCACHE_VIRT_END' failed at domain_page.c:349 (XEN) ----[ Xen-4.10-unstable x86_64 debug=y Tainted: C ]---- (XEN) CPU: 1 (XEN) RIP: e008:[] domain_page_map_to_mfn+0x98/0xc8 (XEN) RFLAGS: 0000000000010012 CONTEXT: hypervisor (XEN) rax: 000000d040200000 rbx: 000000000009e400 rcx: 0000000000000000 (XEN) rdx: 0000001080200000 rsi: 000000009e677000 rdi: ffff82d080200000 (XEN) rbp: ffff84842789fe18 rsp: ffff84842789fe18 r8: ffff8484278d83c0 (XEN) r9: 0000000000000004 r10: 0000000000000001 r11: 0000000000000001 (XEN) r12: ffff82d080200000 r13: ffff84843e220ab0 r14: 00000009b3af6068 (XEN) r15: 00000000ffffffff cr0: 000000008005003b cr4: 00000000000426e0 (XEN) cr3: 000000009e677000 cr2: ffff8800078d4328 (XEN) ds: 002b es: 002b fs: 0000 gs: 0000 ss: e010 cs: e008 (XEN) Xen code around (domain_page_map_to_mfn+0x98/0xc8): (XEN) 48 3d ff ff ff 1f 76 04 <0f> 0b eb fe 48 c1 e7 10 48 c1 ef 1c 48 b8 00 00 (XEN) Xen stack trace from rsp=ffff84842789fe18: (XEN) ffff84842789fe38 ffff82d080286d05 0000000000000001 ffff82d08060b180 (XEN) ffff84842789fe88 ffff82d08021b8b6 ffff84842789fe58 ffff82d0802395a5 (XEN) 000000000000000d ffff84843e220bf0 ffff84843e220ab0 ffff84843e220bf0 (XEN) ffff84843e220ab0 00000009b3af6068 ffff84842789feb8 ffff82d08021bc38 (XEN) 0000000000000001 0000000000000001 ffff84843e220ab0 ffff84843e220ab0 (XEN) ffff84842789ff08 ffff82d08021befa ffff84842789fed8 0000000000000246 (XEN) 0000000000000000 ffff84809e9a5000 0000000000000001 ffff84809e6de000 (XEN) ffff84842788c000 00000000ffffffff ffff84842789fd78 ffff82d08027d4e4 (XEN) ffff8800394b6000 ffff8800394b6002 0000000000000000 0000000000000000 (XEN) ffffc900005f3e60 0000000000000001 0000000000000246 0000000000000000 (XEN) 0000000000000000 000000009b810048 0000000000000000 ffffffff810013aa (XEN) 0000000000000001 deadbeefdeadf00d deadbeefdeadf00d 0000010000000000 (XEN) ffffffff810013aa 000000000000e033 0000000000000246 ffffc900005f3e48 (XEN) 000000000000e02b 42f0e7438e1e7fc8 06c64a65b2da83f9 6ddeafb16f2755f2 (XEN) 97e5fcb4dae8d065 ea89d67a00000001 ffff84809e9a5000 000001b3b6129680 (XEN) 00000000000426e0 (XEN) Xen call trace: (XEN) [] domain_page_map_to_mfn+0x98/0xc8 (XEN) [] arch_livepatch_lookup_mfn+0x46/0x61 (XEN) [] livepatch.c#livepatch_quiesce+0x45/0x1e4 (XEN) [] livepatch.c#apply_payload+0x3f/0x109 (XEN) [] check_for_livepatch_work+0x1f8/0x395 (XEN) [] domain.c#continue_idle_domain+0x1b/0x22 (XEN) (XEN) (XEN) **************************************** (XEN) Panic on CPU 1: (XEN) Assertion 'va >= MAPCACHE_VIRT_START && va < MAPCACHE_VIRT_END' failed at domain_page.c:349 (XEN) **************************************** (XEN) (XEN) Reboot in five seconds... Which is due to: 287 start = (void *)xen_virt_end; 288 end = (void *)(XEN_VIRT_END - NR_CPUS * PAGE_SIZE); 289 290 BUG_ON(end <= start); 291 292 vm_init_type(VMAP_XEN, start, end); If I modify it a bit: diff --git a/xen/arch/x86/domain_page.c b/xen/arch/x86/domain_page.c index 3432a854dd..a95e95b372 100644 --- a/xen/arch/x86/domain_page.c +++ b/xen/arch/x86/domain_page.c @@ -344,6 +344,11 @@ unsigned long domain_page_map_to_mfn(const void *ptr) pl1e = virt_to_xen_l1e(va); BUG_ON(!pl1e); } + else if ( va >= xen_virt_end && va < (XEN_VIRT_END - NR_CPUS * PAGE_SIZE) ) + { + pl1e = virt_to_xen_l1e(va); + BUG_ON(!pl1e); + } else { ASSERT(va >= MAPCACHE_VIRT_START && va < MAPCACHE_VIRT_END);