From patchwork Wed May 22 13:17:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13670854 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36BDFC25B7A for ; Wed, 22 May 2024 13:17:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.727615.1132166 (Exim 4.92) (envelope-from ) id 1s9lqD-0007Oy-9r; Wed, 22 May 2024 13:17:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 727615.1132166; Wed, 22 May 2024 13:17:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9lqD-0007Op-6W; Wed, 22 May 2024 13:17:13 +0000 Received: by outflank-mailman (input) for mailman id 727615; Wed, 22 May 2024 13:17:12 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9lqB-00078O-W5 for xen-devel@lists.xenproject.org; Wed, 22 May 2024 13:17:11 +0000 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [2607:f8b0:4864:20::12c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 989a55e4-183d-11ef-90a0-e314d9c70b13; Wed, 22 May 2024 15:17:11 +0200 (CEST) Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-36dc410c051so23575535ab.2 for ; Wed, 22 May 2024 06:17:11 -0700 (PDT) Received: from andrew-laptop.citrite.net ([160.101.139.1]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43df8308580sm168782291cf.66.2024.05.22.06.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 06:17:09 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 989a55e4-183d-11ef-90a0-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1716383829; x=1716988629; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3W9egxiDkbfNPkqbiYstXvWaWDLlMru2YaLPYeMLJk4=; b=Eey/lI36tR/Hw9I3ReTw348HbWmFKf1OAoYmRsRv6C+KDRmywg9x93q7jAsPiUyC/3 WBSdx/e9ulXeTDRNxdcefLuIChiHYSCXKcyEoVp4LjSP3GZTAEWYYjV78UXrpwZN5YWP 3QbGdTeD7PtUzUyuYU2I4yh9EABQMLtFuTJPY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716383829; x=1716988629; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3W9egxiDkbfNPkqbiYstXvWaWDLlMru2YaLPYeMLJk4=; b=wks4rv/mVW2yeCZu6H2407IQs4iCy1JtoBeqW2RjI3aG3kKieEhipY9d7Gmmn75Ols tcIFEVmmJH87b1KnVW48LycShx6+f7mxr+T+hC7Od2AKBmVqb4W2KeeFBun4UbgW0S90 A8ZTTVAM3EK4JSN5jhuLlv7vn/I5C7qLzciYXGgGWzVsy9Jsg4Kro0Q3xzGsf4MwI7wH yqoDFMSC03Ebe/mYGHmlWvTttquO+veiMMG9ucxRIL9hfTBNp42zbqBSIYXfb11En2kA rUCIB1XCxxEyVU898fqkhHIPgGI3WwQs30s0dLCgFaHzN68QD8Y1/3zRcYBzMxP7lMDr MBjw== X-Gm-Message-State: AOJu0YyYyHHyNydMfJu5+NqVxJPnOYs9YpjANC4kPKQMhInWY7fYKVW7 hraWGk0Xs9Nx/DfqLMn1nnmhRqrU6RVE+hTB2Trz/BPnsF7qQMJEn+cTjDWGxVcYYagx/FG4VCO EkXc= X-Google-Smtp-Source: AGHT+IFOsCZnn3ppdQFR01k/LArnvWpuwcO8Lm9Aw5tWCalNjdTDf2rT+KGQTsBatgJy6F4Dp1WTHg== X-Received: by 2002:a05:6e02:1a2a:b0:36b:1e1:552f with SMTP id e9e14a558f8ab-371faf56c05mr22422715ab.23.1716383829497; Wed, 22 May 2024 06:17:09 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , George Dunlap Subject: [PATCH v2 1/4] x86/shadow: Rework trace_shadow_gen() into sh_trace_va() Date: Wed, 22 May 2024 14:17:00 +0100 Message-Id: <20240522131703.30839-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522131703.30839-1-andrew.cooper3@citrix.com> References: <20240522131703.30839-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 The ((GUEST_PAGING_LEVELS - 2) << 8) expression in the event field is common to all shadow trace events, so introduce sh_trace() as a very thin wrapper around trace(). Then, rename trace_shadow_gen() to sh_trace_va() to better describe what it is doing, and to be more consistent with later cleanup. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monné CC: George Dunlap v2: * New --- xen/arch/x86/mm/shadow/multi.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c index bcd02b2d0037..1775952d7e18 100644 --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -1974,13 +1974,17 @@ typedef u32 guest_va_t; typedef u32 guest_pa_t; #endif -static inline void trace_shadow_gen(u32 event, guest_va_t va) +/* Shadow trace event with GUEST_PAGING_LEVELS folded into the event field. */ +static void sh_trace(uint32_t event, unsigned int extra, const void *extra_data) +{ + trace(event | ((GUEST_PAGING_LEVELS - 2) << 8), extra, extra_data); +} + +/* Shadow trace event with the guest's linear address. */ +static void sh_trace_va(uint32_t event, guest_va_t va) { if ( tb_init_done ) - { - event |= (GUEST_PAGING_LEVELS-2)<<8; - trace(event, sizeof(va), &va); - } + sh_trace(event, sizeof(va), &va); } static inline void trace_shadow_fixup(guest_l1e_t gl1e, @@ -2239,7 +2243,7 @@ static int cf_check sh_page_fault( sh_reset_early_unshadow(v); perfc_incr(shadow_fault_fast_gnp); SHADOW_PRINTK("fast path not-present\n"); - trace_shadow_gen(TRC_SHADOW_FAST_PROPAGATE, va); + sh_trace_va(TRC_SHADOW_FAST_PROPAGATE, va); return 0; } #ifdef CONFIG_HVM @@ -2250,7 +2254,7 @@ static int cf_check sh_page_fault( perfc_incr(shadow_fault_fast_mmio); SHADOW_PRINTK("fast path mmio %#"PRIpaddr"\n", gpa); sh_reset_early_unshadow(v); - trace_shadow_gen(TRC_SHADOW_FAST_MMIO, va); + sh_trace_va(TRC_SHADOW_FAST_MMIO, va); return handle_mmio_with_translation(va, gpa >> PAGE_SHIFT, access) ? EXCRET_fault_fixed : 0; #else @@ -2265,7 +2269,7 @@ static int cf_check sh_page_fault( * Retry and let the hardware give us the right fault next time. */ perfc_incr(shadow_fault_fast_fail); SHADOW_PRINTK("fast path false alarm!\n"); - trace_shadow_gen(TRC_SHADOW_FALSE_FAST_PATH, va); + sh_trace_va(TRC_SHADOW_FALSE_FAST_PATH, va); return EXCRET_fault_fixed; } } @@ -2481,7 +2485,7 @@ static int cf_check sh_page_fault( #endif paging_unlock(d); put_gfn(d, gfn_x(gfn)); - trace_shadow_gen(TRC_SHADOW_DOMF_DYING, va); + sh_trace_va(TRC_SHADOW_DOMF_DYING, va); return 0; } @@ -2569,7 +2573,7 @@ static int cf_check sh_page_fault( put_gfn(d, gfn_x(gfn)); perfc_incr(shadow_fault_mmio); - trace_shadow_gen(TRC_SHADOW_MMIO, va); + sh_trace_va(TRC_SHADOW_MMIO, va); return handle_mmio_with_translation(va, gpa >> PAGE_SHIFT, access) ? EXCRET_fault_fixed : 0; From patchwork Wed May 22 13:17:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13670855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63575C25B7D for ; Wed, 22 May 2024 13:17:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.727616.1132176 (Exim 4.92) (envelope-from ) id 1s9lqF-0007iM-I7; Wed, 22 May 2024 13:17:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 727616.1132176; Wed, 22 May 2024 13:17:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9lqF-0007iF-FE; Wed, 22 May 2024 13:17:15 +0000 Received: by outflank-mailman (input) for mailman id 727616; Wed, 22 May 2024 13:17:13 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9lqD-00078O-9R for xen-devel@lists.xenproject.org; Wed, 22 May 2024 13:17:13 +0000 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [2607:f8b0:4864:20::832]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 999cc691-183d-11ef-90a0-e314d9c70b13; Wed, 22 May 2024 15:17:12 +0200 (CEST) Received: by mail-qt1-x832.google.com with SMTP id d75a77b69052e-43e0d564136so7661601cf.0 for ; Wed, 22 May 2024 06:17:12 -0700 (PDT) Received: from andrew-laptop.citrite.net ([160.101.139.1]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43df8308580sm168782291cf.66.2024.05.22.06.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 06:17:10 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 999cc691-183d-11ef-90a0-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1716383831; x=1716988631; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dUgjIaJwGOveqC8f3Hnlrm+bkXv3Lg6iNL+SZwb8N6Q=; b=V4h8tgLYHMop/DKO1BRIOprCKj0pyhJ5pK7ffsWc5tf/JHY2v7rdIWQ3xd+v2UZ8Nd DzwqZmm+cFayVRF8VjUqi4xDzImgKRyZYswdkl0qWTEO537U4lXsipalOlScHQqNh9GX QGwyj4QFS56aHw+jyXKrbstop3ZKJPWiAxQlA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716383831; x=1716988631; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dUgjIaJwGOveqC8f3Hnlrm+bkXv3Lg6iNL+SZwb8N6Q=; b=XBP6DtBHMk+nXSOP1lqtJ0KlbCRIE6KVRbVAfZGRHkynvpHgdXKAAsQqg2r+to54X1 ccdzROXwWL711OkGGeM0Sv/FVYHbVw07spC09XSWuCWoH5n530cEquJQo504+3ljO9q2 heoA3qpK9+eRWZ80YFU2lhUF9LGTOwy7qjQWEDaK7YaVqlknuviG32eqP06A8ofXZ6wC U/YsXU9CUdqRwKDiUEAl4mH7Hr2e8zfqFdaapoDadqHiNerXWPeJ6nqRc9wINtn/YnZk o4qV7CtaqQWHLANJfU1sZWBNo/q1buS1hOhT19N1ZNFDhNHsNR8PgUQggdLUgqjrRoIz WWHg== X-Gm-Message-State: AOJu0YwR9EXav6bA+min5XC4udOac5RFYKjra0uzpOpgYrQMNzvjaQ1y +9A3don/AuRM+IqjUQSrhBDrB02FC+f2yVk3XL6WYdpMeOFf7weDPDTJGvVFIgh3CHcCN9A8w6Z dntY= X-Google-Smtp-Source: AGHT+IE058XLU1M59pKmCtXLyedictXtR2d3bLBkWZ1fCtR64oB4lj/5qgOU1e77TQNhYbhybjhYnA== X-Received: by 2002:ac8:5e49:0:b0:43a:ecfb:8a5c with SMTP id d75a77b69052e-43f9e124359mr28617561cf.40.1716383831009; Wed, 22 May 2024 06:17:11 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , George Dunlap Subject: [PATCH v2 2/4] x86/shadow: Introduce sh_trace_gl1e_va() Date: Wed, 22 May 2024 14:17:01 +0100 Message-Id: <20240522131703.30839-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522131703.30839-1-andrew.cooper3@citrix.com> References: <20240522131703.30839-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 trace_shadow_fixup() and trace_not_shadow_fault() both write out identical trace records. Reimplement them in terms of a common sh_trace_gl1e_va(). There's no need to pack the trace record, even in the case of PAE paging. No functional change. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monné CC: George Dunlap v2: * New --- xen/arch/x86/mm/shadow/multi.c | 59 ++++++++++------------------------ 1 file changed, 17 insertions(+), 42 deletions(-) diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c index 1775952d7e18..f0a9cc527c0b 100644 --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -1987,51 +1987,26 @@ static void sh_trace_va(uint32_t event, guest_va_t va) sh_trace(event, sizeof(va), &va); } -static inline void trace_shadow_fixup(guest_l1e_t gl1e, - guest_va_t va) +/* Shadow trace event with a gl1e, linear address and flags. */ +static void sh_trace_gl1e_va(uint32_t event, guest_l1e_t gl1e, guest_va_t va) { if ( tb_init_done ) { - struct __packed { - /* for PAE, guest_l1e may be 64 while guest_va may be 32; - so put it first for alignment sake. */ - guest_l1e_t gl1e; - guest_va_t va; - u32 flags; - } d; - u32 event; - - event = TRC_SHADOW_FIXUP | ((GUEST_PAGING_LEVELS-2)<<8); - - d.gl1e = gl1e; - d.va = va; - d.flags = this_cpu(trace_shadow_path_flags); - - trace(event, sizeof(d), &d); - } -} - -static inline void trace_not_shadow_fault(guest_l1e_t gl1e, - guest_va_t va) -{ - if ( tb_init_done ) - { - struct __packed { - /* for PAE, guest_l1e may be 64 while guest_va may be 32; - so put it first for alignment sake. */ + struct { + /* + * For GUEST_PAGING_LEVELS=3 (PAE paging), guest_l1e is 64 while + * guest_va is 32. Put it first to avoid padding. + */ guest_l1e_t gl1e; guest_va_t va; - u32 flags; - } d; - u32 event; - - event = TRC_SHADOW_NOT_SHADOW | ((GUEST_PAGING_LEVELS-2)<<8); - - d.gl1e = gl1e; - d.va = va; - d.flags = this_cpu(trace_shadow_path_flags); - - trace(event, sizeof(d), &d); + uint32_t flags; + } d = { + .gl1e = gl1e, + .va = va, + .flags = this_cpu(trace_shadow_path_flags), + }; + + sh_trace(event, sizeof(d), &d); } } @@ -2603,7 +2578,7 @@ static int cf_check sh_page_fault( d->arch.paging.log_dirty.fault_count++; sh_reset_early_unshadow(v); - trace_shadow_fixup(gw.l1e, va); + sh_trace_gl1e_va(TRC_SHADOW_FIXUP, gw.l1e, va); done: __maybe_unused; sh_audit_gw(v, &gw); SHADOW_PRINTK("fixed\n"); @@ -2857,7 +2832,7 @@ static int cf_check sh_page_fault( put_gfn(d, gfn_x(gfn)); propagate: - trace_not_shadow_fault(gw.l1e, va); + sh_trace_gl1e_va(TRC_SHADOW_NOT_SHADOW, gw.l1e, va); return 0; } From patchwork Wed May 22 13:17:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13670856 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7213EC25B7C for ; Wed, 22 May 2024 13:17:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.727617.1132186 (Exim 4.92) (envelope-from ) id 1s9lqG-000804-Vt; Wed, 22 May 2024 13:17:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 727617.1132186; Wed, 22 May 2024 13:17:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9lqG-0007zt-SG; Wed, 22 May 2024 13:17:16 +0000 Received: by outflank-mailman (input) for mailman id 727617; Wed, 22 May 2024 13:17:15 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9lqF-0006aV-NS for xen-devel@lists.xenproject.org; Wed, 22 May 2024 13:17:15 +0000 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [2607:f8b0:4864:20::82d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9a689107-183d-11ef-b4bb-af5377834399; Wed, 22 May 2024 15:17:14 +0200 (CEST) Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-43f91aac792so5822751cf.1 for ; Wed, 22 May 2024 06:17:14 -0700 (PDT) Received: from andrew-laptop.citrite.net ([160.101.139.1]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43df8308580sm168782291cf.66.2024.05.22.06.17.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 06:17:12 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9a689107-183d-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1716383832; x=1716988632; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oUlYslBBFz8SJFw2HFYr2U4IW4XAKwPKEvjfJVvwvsQ=; b=j1fHsoszGxka524cwGAFbgs2MRpdTBw+DZlVvfJw1OJT+j+y612ZV9xcYZJyn+ixyP Kg7ryvhWPeB6EHsNzltpY6qoVMKw/r5gw2Q6DVU/o70NsM6VSzdce2c4TS3m8qrlZMSm Yf0/+wgEKzHI9YRLln9ZHLNrTThNQiApp6Ggc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716383832; x=1716988632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oUlYslBBFz8SJFw2HFYr2U4IW4XAKwPKEvjfJVvwvsQ=; b=mxlzf9j7L/CUYb9ZXxENmtYvxSmw7qh5Kh+aIH8Ko9F1R0n3AtNpNJDpNrUXBRpWhd eixcjpWjnNZC3Bw6/9R3kwd6OPOlAGHMbn8kIjgepnAPg+ena7+xl21BU8OT/yOHd95V D25j0CQNmcYdrQOp7Koj0EMZ/okT13AMOqY8kyn8xUC6ZB4ka+IBzsWKhTOLVr+JZs+i +RT+KA1IQEMAVAcxu2eZxmmCQulTOSXDvtNF/RCOtU0C8gNxSVYtTjq/ZltWOdtdk0jI sQWv/Kbd3dNkVUl9rZthZx9CbQGKrIWUXY2a7c59s/izbKyuQDe9KacaYZJ80sYhisZS Azeg== X-Gm-Message-State: AOJu0Yze0GC9Ufr8GIgwi2IpOT6sIcfmuupiQsl5QTA1tKuDSEuAW6WL l1IO5Zlbg9xoPhBDzIddVqMDjBv/r3FN6ETZ7QNwLHmPWlUuzz0iVm6jeHXPQxaJy06g/wbmetc /UT8= X-Google-Smtp-Source: AGHT+IHgcNFz0cHXAnovqybxYLcIlXH3BYwKJQGW2bzSQcH9gB41flGGy3toNyocqY82GQ5X3vsOTw== X-Received: by 2002:ac8:598e:0:b0:43a:3fce:32c2 with SMTP id d75a77b69052e-43f7a28dfd5mr195215021cf.3.1716383832534; Wed, 22 May 2024 06:17:12 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , George Dunlap Subject: [PATCH v2 3/4] x86/shadow: Rework trace_shadow_emulate_other() as sh_trace_gfn_va() Date: Wed, 22 May 2024 14:17:02 +0100 Message-Id: <20240522131703.30839-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522131703.30839-1-andrew.cooper3@citrix.com> References: <20240522131703.30839-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 sh_trace_gfn_va() is very similar to sh_trace_gl1e_va(), and a rather shorter name than trace_shadow_emulate_other(). Like sh_trace_gl1e_va(), there is no need to pack the trace record. No functional change. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monné CC: George Dunlap v2: * New --- xen/arch/x86/mm/shadow/multi.c | 40 ++++++++++++++++------------------ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c index f0a9cc527c0b..d2fe4e148fe0 100644 --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -2010,29 +2010,30 @@ static void sh_trace_gl1e_va(uint32_t event, guest_l1e_t gl1e, guest_va_t va) } } -static inline void trace_shadow_emulate_other(u32 event, - guest_va_t va, - gfn_t gfn) +/* Shadow trace event with a gfn, linear address and flags. */ +static void sh_trace_gfn_va(uint32_t event, gfn_t gfn, guest_va_t va) { if ( tb_init_done ) { - struct __packed { - /* for PAE, guest_l1e may be 64 while guest_va may be 32; - so put it first for alignment sake. */ + struct { + /* + * For GUEST_PAGING_LEVELS=3 (PAE paging), gfn is 64 while + * guest_va is 32. Put it first to avoid padding. + */ #if GUEST_PAGING_LEVELS == 2 - u32 gfn; + uint32_t gfn; #else - u64 gfn; + uint64_t gfn; #endif guest_va_t va; - } d; - - event |= ((GUEST_PAGING_LEVELS-2)<<8); - - d.gfn=gfn_x(gfn); - d.va = va; + uint32_t flags; + } d = { + .gfn = gfn_x(gfn), + .va = va, + .flags = this_cpu(trace_shadow_path_flags), + }; - trace(event, sizeof(d), &d); + sh_trace(event, sizeof(d), &d); } } @@ -2603,8 +2604,7 @@ static int cf_check sh_page_fault( mfn_x(gmfn)); perfc_incr(shadow_fault_emulate_failed); shadow_remove_all_shadows(d, gmfn); - trace_shadow_emulate_other(TRC_SHADOW_EMULATE_UNSHADOW_USER, - va, gfn); + sh_trace_gfn_va(TRC_SHADOW_EMULATE_UNSHADOW_USER, gfn, va); goto done; } @@ -2683,8 +2683,7 @@ static int cf_check sh_page_fault( } #endif shadow_remove_all_shadows(d, gmfn); - trace_shadow_emulate_other(TRC_SHADOW_EMULATE_UNSHADOW_EVTINJ, - va, gfn); + sh_trace_gfn_va(TRC_SHADOW_EMULATE_UNSHADOW_EVTINJ, gfn, va); return EXCRET_fault_fixed; } @@ -2739,8 +2738,7 @@ static int cf_check sh_page_fault( * though, this is a hint that this page should not be shadowed. */ shadow_remove_all_shadows(d, gmfn); - trace_shadow_emulate_other(TRC_SHADOW_EMULATE_UNSHADOW_UNHANDLED, - va, gfn); + sh_trace_gfn_va(TRC_SHADOW_EMULATE_UNSHADOW_UNHANDLED, gfn, va); goto emulate_done; } From patchwork Wed May 22 13:17:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13670857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EB4F1C25B7A for ; Wed, 22 May 2024 13:17:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.727619.1132196 (Exim 4.92) (envelope-from ) id 1s9lqI-0008HN-8l; Wed, 22 May 2024 13:17:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 727619.1132196; Wed, 22 May 2024 13:17:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9lqI-0008HG-4Y; Wed, 22 May 2024 13:17:18 +0000 Received: by outflank-mailman (input) for mailman id 727619; Wed, 22 May 2024 13:17:16 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s9lqG-00078O-GN for xen-devel@lists.xenproject.org; Wed, 22 May 2024 13:17:16 +0000 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [2607:f8b0:4864:20::82b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9b8a0971-183d-11ef-90a0-e314d9c70b13; Wed, 22 May 2024 15:17:16 +0200 (CEST) Received: by mail-qt1-x82b.google.com with SMTP id d75a77b69052e-43df23e034cso8450601cf.0 for ; Wed, 22 May 2024 06:17:15 -0700 (PDT) Received: from andrew-laptop.citrite.net ([160.101.139.1]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43df8308580sm168782291cf.66.2024.05.22.06.17.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 06:17:14 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9b8a0971-183d-11ef-90a0-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1716383834; x=1716988634; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SKZ+hrKbmIX0HLzcZm1/QsXM9UY491uFgrKkXcJYF8Y=; b=b5ixs+yXSJvIAMvV6U0JtXbWd4UiuYeQCP2XjgRiHSV93S910EES0Sh4LO917RwJeK gXsfXq005oziqc4nEa4zm6GEUlR30Kwj3ZpY0huD3WjN++jRREGUJMIM33/6CX9ZUdm1 Lm1x/rGiSxj/V21kVaI7lp+QtwM1vVbjQQ/A8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716383834; x=1716988634; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SKZ+hrKbmIX0HLzcZm1/QsXM9UY491uFgrKkXcJYF8Y=; b=QeE7x+0n6OSsxH9fxj6pNtTHXHp7ThJGm84Ua6t8GY106uq7bBeLk+pmtC/si51nGx JIIojxRJK5H6d9N5jMCv6YFD9JdsxUljq1zYfpIebBMR2D/jc5A30JiqTPuJXmaaJvbr c8HOg5RKcGJay83DrjOQ8xTQppXQ73vLdaOW2LLX1e8ZAyF8ZGDM6TxrucYxPnqnwoAJ F3KDoHd0ZwsIJ9UIZ414DiPAQ1MwvEnyMH/RUcsYxUbAH5eiBMBzInwKQToN329vQ28K UfUSTnBts3CImt8ra04RKJeVnJ/CNST/HyoNInimox2sbtvdRMbnlTuW7CVjYcb/bKwX OZiw== X-Gm-Message-State: AOJu0YyEZfy5vr+ed1XvOIFeOmyFBaz7yFbTW1cgU77FHE21AK5VYq5R 4qpmv/mgpwpLXYRiZ84JR/8JmvfIqnbd35arqW4TDnv0eHL39UipczhsDHahmwLzeaxSy46SPJB 8Awc= X-Google-Smtp-Source: AGHT+IElu8z/Eu8w8c3oL9QCc/0cb9N1XmB+dL6SmIf139Vn5/gJPiYk1pYs35eiOA29ZFkoAO+0Tw== X-Received: by 2002:a05:622a:4:b0:43a:7b64:2fcc with SMTP id d75a77b69052e-43f7a29127dmr242246561cf.7.1716383834375; Wed, 22 May 2024 06:17:14 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Jan Beulich , George Dunlap Subject: [PATCH v2 4/4] x86/shadow: Don't leave trace record field uninitialized Date: Wed, 22 May 2024 14:17:03 +0100 Message-Id: <20240522131703.30839-5-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522131703.30839-1-andrew.cooper3@citrix.com> References: <20240522131703.30839-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 From: Jan Beulich The emulation_count field is set only conditionally right now. Convert all field setting to an initializer, thus guaranteeing that field to be set to 0 (default initialized) when GUEST_PAGING_LEVELS != 3. Rework trace_shadow_emulate() to be consistent with the other trace helpers. Coverity-ID: 1598430 Fixes: 9a86ac1aa3d2 ("xentrace 5/7: Additional tracing for the shadow code") Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné Acked-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monné CC: George Dunlap v2: * Rebase over packing/sh_trace() cleanup. --- xen/arch/x86/mm/shadow/multi.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c index d2fe4e148fe0..47dd1cc626b2 100644 --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -2063,30 +2063,29 @@ static void cf_check trace_emulate_write_val( #endif } -static inline void trace_shadow_emulate(guest_l1e_t gl1e, unsigned long va) +static inline void sh_trace_emulate(guest_l1e_t gl1e, unsigned long va) { if ( tb_init_done ) { - struct __packed { - /* for PAE, guest_l1e may be 64 while guest_va may be 32; - so put it first for alignment sake. */ + struct { + /* + * For GUEST_PAGING_LEVELS=3 (PAE paging), guest_l1e is 64 while + * guest_va is 32. Put it first to avoid padding. + */ guest_l1e_t gl1e, write_val; guest_va_t va; uint32_t flags:29, emulation_count:3; - } d; - u32 event; - - event = TRC_SHADOW_EMULATE | ((GUEST_PAGING_LEVELS-2)<<8); - - d.gl1e = gl1e; - d.write_val.l1 = this_cpu(trace_emulate_write_val); - d.va = va; + } d = { + .gl1e = gl1e, + .write_val.l1 = this_cpu(trace_emulate_write_val), + .va = va, #if GUEST_PAGING_LEVELS == 3 - d.emulation_count = this_cpu(trace_extra_emulation_count); + .emulation_count = this_cpu(trace_extra_emulation_count), #endif - d.flags = this_cpu(trace_shadow_path_flags); + .flags = this_cpu(trace_shadow_path_flags), + }; - trace(event, sizeof(d), &d); + sh_trace(TRC_SHADOW_EMULATE, sizeof(d), &d); } } #endif /* CONFIG_HVM */ @@ -2815,7 +2814,7 @@ static int cf_check sh_page_fault( } #endif /* PAE guest */ - trace_shadow_emulate(gw.l1e, va); + sh_trace_emulate(gw.l1e, va); emulate_done: SHADOW_PRINTK("emulated\n"); return EXCRET_fault_fixed;