From patchwork Thu Dec 19 03:40:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13914436 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 B8DF6E7718B for ; Thu, 19 Dec 2024 03:41:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tO7P8-00071e-HA; Wed, 18 Dec 2024 22:40:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tO7P7-00071K-0O; Wed, 18 Dec 2024 22:40:49 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tO7P5-0004I2-Fe; Wed, 18 Dec 2024 22:40:48 -0500 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-21661be2c2dso2811105ad.1; Wed, 18 Dec 2024 19:40:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734579645; x=1735184445; darn=nongnu.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=bMMfLBkMrY+DVueinUNWjTYlxFYKuSCnv3bBp02CQwM=; b=U2Y92zaV5fGD5GM0qatzVdDrcZoaW1Pm4jkrcrQyr3IDzP62aOuWO1mSIZonBChThp b/20kPfuW7FbLTW4m3k67JlZys7lNIBI6BIBVFUPfakJNskX2qtQtwifN1GbxMnTOGGT zp65Kv1BnDcA4KpDzCx0zjYpS43/Rr8kzKGKZT2i0USzDASPVfvOIacbvLeMSg4+uexi L1K8GdtTxNS3XYuQRNRn3x7RmIb6pIXt5XoI4/7TTsyvphXAkRWTfSeuknrda9nO8ktl IY2UXmg9M3UnHCW0YH8E+1o6bC5ZI0uCl0MKRq6VMwZmEpZ9qJT/uzobow4XBa2zB9Fn AycA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734579645; x=1735184445; 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=bMMfLBkMrY+DVueinUNWjTYlxFYKuSCnv3bBp02CQwM=; b=t5if93kib7S4HeFTw4ley4KzhaD83cIKHpkwg/EmsUzdjs1WzsSF5NLrVGkxtJd+M4 nK2ruWswlE25JLW/R5hcD+SOvcspkJcuk2qmbAosQMYqG/wYj/EuNP+tBDtYucm5YrvR 6e7+ciXR0NLXzrwjr0SrWN7Hq8i/DtU9xH5KPWJvgtRPxG6oyQCw6BzLacLx8YE7/L/D 7jsp+hN315hEcmLdZ6FCsWNNuU3SZmXw3A/qd/tEbVCeuLI1WvDxSm1xyYO9KqJBOmIY ffi6Ml2hVndmsNKMUx2X0v9poef0D4QgLaG6KPq0KEwjhMkkNjlIql8gjihwaa3LRRBI nRVA== X-Forwarded-Encrypted: i=1; AJvYcCUMPZay9dzk2w/0BSdBn7NQP3z1JZh3bsYsTccQ9YAQEA78noNudo9crZPAm/zQ+jIicgnILJI4luO2@nongnu.org X-Gm-Message-State: AOJu0YyZxYeHFi9+cqBEJN3u+h7TvV++DBsQ3AA8baRZKhaG18uha58f bwZrmlVKvd5oGrtAmA4ylDg7tiTFqBrtr784I94HFSjUm5ROEq1oFdGBbg== X-Gm-Gg: ASbGncuGYTd4Uk5J78xmYV5P/HriNWq/ejuRH89hqJPISnes6u0xWjwKaSjF+UYXzXn H45pDdMWXf8KcIvcMfdX894drUtqZ1+HtNqDVpNavEb/iMTk73xRQMgMX7HMsYytkmlkToyr9LT HmiLzgqeY3nFr0IScf8Gu+rx/sh8R0LK7n9+OCpWLjdfd4TIUWnwQgZc/YPLD7X4z/Lufxj/om/ EIfGZbfkU561ioUH2mLcR/EJFjRAmRwU7nBWP1nwohRbfFOAuGTiAtrt1DzAzMPadt//wVT8/hF 90g/npN9Vw== X-Google-Smtp-Source: AGHT+IHENSiFOOdEy02BNmlcsQw58GCu7Pl88csHFEWpDIAD2ABmzkov+HZv4gu3uEiRhUnzK8aClA== X-Received: by 2002:a17:902:f541:b0:216:6769:9ed7 with SMTP id d9443c01a7336-219d96928bbmr33144815ad.40.1734579645535; Wed, 18 Dec 2024 19:40:45 -0800 (PST) Received: from wheely.local0.net (14-200-18-130.tpgi.com.au. [14.200.18.130]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc970520sm2881595ad.75.2024.12.18.19.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 19:40:45 -0800 (PST) From: Nicholas Piggin To: qemu-ppc@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , qemu-devel@nongnu.org Subject: [PATCH 1/5] target/ppc: fix timebase register reset state Date: Thu, 19 Dec 2024 13:40:31 +1000 Message-ID: <20241219034035.1826173-2-npiggin@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241219034035.1826173-1-npiggin@gmail.com> References: <20241219034035.1826173-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=npiggin@gmail.com; helo=mail-pl1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org (H)DEC and PURR get reset before icount does, which causes them to be skewed and not match the init state. This can cause replay to not match the recorded trace exactly. For DEC and HDEC this is usually not noticable since they tend to get programmed before affecting the target machine. PURR has been observed to cause replay bugs when running Linux. Fix this by resetting using a time of 0. Signed-off-by: Nicholas Piggin --- hw/ppc/ppc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index b86b5847de6..51ae3358d12 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -1123,16 +1123,21 @@ void cpu_ppc_tb_reset(CPUPPCState *env) timer_del(tb_env->hdecr_timer); ppc_set_irq(cpu, PPC_INTERRUPT_HDECR, 0); tb_env->hdecr_next = 0; + _cpu_ppc_store_hdecr(cpu, 0, 0, 0, 64); } /* * There is a bug in Linux 2.4 kernels: * if a decrementer exception is pending when it enables msr_ee at startup, * it's not ready to handle it... + * + * On machine reset, this is called before icount is reset, so for + * icount-mode, setting TB registers using now == qemu_clock_get_ns() + * results in them being garbage after icount is reset. Use an + * explicit now == 0 to get a consistent reset state. */ - cpu_ppc_store_decr(env, -1); - cpu_ppc_store_hdecr(env, -1); - cpu_ppc_store_purr(env, 0x0000000000000000ULL); + _cpu_ppc_store_decr(cpu, 0, 0, -1, 64); + _cpu_ppc_store_purr(env, 0, 0); } void cpu_ppc_tb_free(CPUPPCState *env) From patchwork Thu Dec 19 03:40:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13914434 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 EC197E77184 for ; Thu, 19 Dec 2024 03:41:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tO7PB-000745-PU; Wed, 18 Dec 2024 22:40:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tO7PA-00072A-4x; Wed, 18 Dec 2024 22:40:52 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tO7P8-0004IR-Ek; Wed, 18 Dec 2024 22:40:51 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2166f1e589cso3871365ad.3; Wed, 18 Dec 2024 19:40:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734579648; x=1735184448; darn=nongnu.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=Wq3Jl1AW0pq6Ra+sjmnRZba6A1rNlSx3/9ckGBwUM5k=; b=N1I6fBynfxunFEfO3agZjbvaAIghid4dFT0XZW/G2zKld0C5XyFp9fizZaOWaFKsQe pPFB25OZBgy/PBVra1JO0Udp02zRI3pggtpSGZBToTJ8wcgx9tFqORELJg+YoK4hSJAM cyMObqymc1bkbtnIDQlEVknpreZQYK1+sd9wj1uamyLc+Bt6E/8hE6dV0tT9fv8wEBhk 6Yuif5zOcWAbQq/HeRYI3QFJymEjt20lj8LWqJLlezXC1t3yjUlGUHy87jDvctQyDMKF CTJ3cPeo9kH/CmBQUtbsW09v8CGAI7kuAqQUJIagIoC2HW8aCTNFZJmktoSvlEQNcusx 6p2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734579648; x=1735184448; 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=Wq3Jl1AW0pq6Ra+sjmnRZba6A1rNlSx3/9ckGBwUM5k=; b=JrWJsWRPyiZZfZDAnUg1CyqweZKjGrG5du6FZlVhaB1WjH2Nm8WVQVqFN9B+xOPEDp oL8R6RmAqeQQgvSYlovt/OXyVbTwvtjSq1gGfNKtAPLh2Rq3ta6KTIwAB0qHEWukUQyi agGebiensHjegHJzCqaLKre1eB92WbnVNN+yW9eNf9pwKC8bk6vDcs/fru+QzxM4rXxr vu6rxqKngydnHHFMjz5/rKbBoSwJJ1u/ZnRt9Op7l5QuB+EYPSPJSPT9uXhuLcv6PL2B INU6J4SYQ6vwOQFKl1w2wxajAa7A12tdzka3wfTNsVz+NJMy6/3+xvaiv4VgoeBTigqN UGGQ== X-Forwarded-Encrypted: i=1; AJvYcCWO545UsORJXuqKRiQc+lkAk9tqHFjrxftTbOghPbcXcBAiQqksAum8CjABZjppcNgDSXSa2WYFUmb0@nongnu.org X-Gm-Message-State: AOJu0YyIDsR+c4yd+HlTAvtSTVqZik2vdZfw9slWoJQDj8XawKg4GZJs iS9uAEJOB72yQWHg8GKkhtQherxtEMT78exsYgiODyh6+6d7e+CLVAmWjA== X-Gm-Gg: ASbGncuRGhLZNgvFFvAOfLe8gOuK+sU6BkA3/d+bA06lCkJtnzzRiSAgG91awwfAY2h slbmEvHYByloXol9p2UMeW7G6+bxc+ojIf+NaRkGgvVLmkHYny4PIno71H5M+8SRKx6K2labmVw J/TmEmPe8aI4tLg8SYoGtbUzR0DmH+lAVpLnPOJ1nKrwRmJNdQh1Tpv4dAsL+tB+Y/cS/7In+rQ e2aY7mNIleVOqfMZpr60kwiL0mQAAIzo6pOA5UnYJKzch4sw+TtI/vO3IAy3nr2i9rWqj4uvxn/ FTaAGnngmw== X-Google-Smtp-Source: AGHT+IEgl+l2kBLREVhNKE/n+rGiSiHtu/ZEc+oamSnL8zzqkTbnPmWbsC76IBjrhuScDNDKLkwelA== X-Received: by 2002:a17:902:db0f:b0:217:89da:fd54 with SMTP id d9443c01a7336-218d722f88fmr88039025ad.33.1734579648472; Wed, 18 Dec 2024 19:40:48 -0800 (PST) Received: from wheely.local0.net (14-200-18-130.tpgi.com.au. [14.200.18.130]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc970520sm2881595ad.75.2024.12.18.19.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 19:40:48 -0800 (PST) From: Nicholas Piggin To: qemu-ppc@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , qemu-devel@nongnu.org Subject: [PATCH 2/5] spapr: Fix vpa dispatch count for record-replay Date: Thu, 19 Dec 2024 13:40:32 +1000 Message-ID: <20241219034035.1826173-3-npiggin@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241219034035.1826173-1-npiggin@gmail.com> References: <20241219034035.1826173-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=npiggin@gmail.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The dispatch count is a field in guest memory that the hypervisor increments when preempting and dispatching the guest. This was not being done deterministically with respect to icount, because tcg exec exit is not deterministic (e.g., an async event could cause it). Change vpa dispatch count increment to keep track of whether the vCPU is considered dispatched or not, and only consider it preempted when calling cede / confer / join / stop-self / etc. Signed-off-by: Nicholas Piggin --- include/hw/ppc/spapr_cpu_core.h | 3 +++ hw/ppc/spapr.c | 36 ++------------------------------- hw/ppc/spapr_hcall.c | 33 ++++++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 1 + 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h index 68f70834832..feba3446194 100644 --- a/include/hw/ppc/spapr_cpu_core.h +++ b/include/hw/ppc/spapr_cpu_core.h @@ -46,6 +46,7 @@ typedef struct SpaprCpuState { uint64_t vpa_addr; uint64_t slb_shadow_addr, slb_shadow_size; uint64_t dtl_addr, dtl_size; + bool dispatched; /* for vpa dispatch counter tracking */ bool prod; /* not migrated, only used to improve dispatch latencies */ struct ICPState *icp; struct XiveTCTX *tctx; @@ -60,4 +61,6 @@ static inline SpaprCpuState *spapr_cpu_state(PowerPCCPU *cpu) return (SpaprCpuState *)cpu->machine_data; } +void vpa_dispatch(CPUState *cs, SpaprCpuState *spapr_cpu, bool dispatch); + #endif diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 3b022e8da9e..fa05e0c5156 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -4519,47 +4519,15 @@ static void spapr_cpu_exec_enter(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu) { SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu); - /* These are only called by TCG, KVM maintains dispatch state */ - spapr_cpu->prod = false; - if (spapr_cpu->vpa_addr) { + if (!spapr_cpu->dispatched) { CPUState *cs = CPU(cpu); - uint32_t dispatch; - - dispatch = ldl_be_phys(cs->as, - spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER); - dispatch++; - if ((dispatch & 1) != 0) { - qemu_log_mask(LOG_GUEST_ERROR, - "VPA: incorrect dispatch counter value for " - "dispatched partition %u, correcting.\n", dispatch); - dispatch++; - } - stl_be_phys(cs->as, - spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER, dispatch); + vpa_dispatch(cs, spapr_cpu, true); } } static void spapr_cpu_exec_exit(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu) { - SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu); - - if (spapr_cpu->vpa_addr) { - CPUState *cs = CPU(cpu); - uint32_t dispatch; - - dispatch = ldl_be_phys(cs->as, - spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER); - dispatch++; - if ((dispatch & 1) != 1) { - qemu_log_mask(LOG_GUEST_ERROR, - "VPA: incorrect dispatch counter value for " - "preempted partition %u, correcting.\n", dispatch); - dispatch++; - } - stl_be_phys(cs->as, - spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER, dispatch); - } } static void spapr_machine_class_init(ObjectClass *oc, void *data) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 5e1d020e3df..907e09c2c36 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -487,6 +487,36 @@ static target_ulong h_register_vpa(PowerPCCPU *cpu, SpaprMachineState *spapr, return ret; } +void vpa_dispatch(CPUState *cs, SpaprCpuState *spapr_cpu, bool dispatch) +{ + uint32_t counter; + + if (!dispatch) { + assert(spapr_cpu->dispatched); + } else { + assert(!spapr_cpu->dispatched); + } + spapr_cpu->dispatched = dispatch; + + return; + + if (!spapr_cpu->vpa_addr) { + return; + } + + /* These are only called by TCG, KVM maintains dispatch state */ + counter = ldl_be_phys(cs->as, spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER); + counter++; + if ((counter & 1) != dispatch) { + qemu_log_mask(LOG_GUEST_ERROR, + "VPA: incorrect dispatch counter value for " + "%s partition %u, correcting.\n", + dispatch ? "preempted" : "running", counter); + counter++; + } + stl_be_phys(cs->as, spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER, counter); +} + static target_ulong h_cede(PowerPCCPU *cpu, SpaprMachineState *spapr, target_ulong opcode, target_ulong *args) { @@ -505,6 +535,7 @@ static target_ulong h_cede(PowerPCCPU *cpu, SpaprMachineState *spapr, if (!cpu_has_work(cs)) { cs->halted = 1; + vpa_dispatch(cs, spapr_cpu, false); cs->exception_index = EXCP_HLT; cs->exit_request = 1; ppc_maybe_interrupt(env); @@ -531,6 +562,8 @@ static target_ulong h_confer_self(PowerPCCPU *cpu) cs->exit_request = 1; ppc_maybe_interrupt(&cpu->env); + vpa_dispatch(cs, spapr_cpu, false); + return H_SUCCESS; } diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index f329693c554..8ce42302234 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -216,6 +216,7 @@ static void rtas_stop_self(PowerPCCPU *cpu, SpaprMachineState *spapr, */ env->spr[SPR_PSSCR] |= PSSCR_EC; cs->halted = 1; + vpa_dispatch(cs, spapr_cpu_state(cpu), false); ppc_store_lpcr(cpu, env->spr[SPR_LPCR] & ~pcc->lpcr_pm); kvmppc_set_reg_ppc_online(cpu, 0); qemu_cpu_kick(cs); From patchwork Thu Dec 19 03:40:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13914437 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 BE9D1E77184 for ; Thu, 19 Dec 2024 03:42:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tO7PF-00075E-VI; Wed, 18 Dec 2024 22:40:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tO7PD-00074w-3h; Wed, 18 Dec 2024 22:40:55 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tO7PB-0004Id-Kp; Wed, 18 Dec 2024 22:40:54 -0500 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-21644aca3a0so3872185ad.3; Wed, 18 Dec 2024 19:40:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734579651; x=1735184451; darn=nongnu.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=zBCJnxrt9+FDevqEKtofQsJcdCi8uOcbq538B+v/z+s=; b=Pvp8JsgV1jhq+2f1FWoxb/XbRjLczR3GSWsgJYwbvIFbPbZoIqvFEDEj0QfIpJxngg Z91D9dojK7d+f2Xt82v9OLELMGfd6btLLT9IX9vee2jeOinus/52JELtFFID2anUsB8A r8lZlCily01lKMwpuRHIj4NNZqjY5enE7O7lfaoIMGVojuxd3zCqzGVqyq00AV9uaSn1 iuBxigm/liVfN5/00CD/xFPppPegUYvDucIoSzKVWVY4dxLI7m31m8Wju/JgwzLltvaP zh3GqkQ0nW2c5hbYJCHFvQyUotW6guRzG4l/aPOVYXVUFFjOH8s9855uG50B37OQst+W sZUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734579651; x=1735184451; 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=zBCJnxrt9+FDevqEKtofQsJcdCi8uOcbq538B+v/z+s=; b=AZHMn6MStqFrsEDnt8KXYdWHPSKxg1TDM2afzcfAQ9OZnGyv6XB1hY7o/TjolA8ej8 kfofFpuPJdGNyj+7iOY6AOVFWOPyZVTwgzFwNXjQ6Lbbasy6pJgFnV9Dsv9OP5ywHNR2 S3o6MBPJ5J3ZSDMjFV/jYMxtzopSYFrJ1xXL5/pBIxEhILwjtU9m6BGAzoh2pwJC7vkm tl0vr24He2TYite/5tm76uPX/ce8vHbcwooTXji1TxNTSjhyQlIjNm2GTg910CnzaHCT 1UVsh/iKr6FHmmS46ZUkXqyYrRLo5+pvHhsF70XU1/3GZ6tcGu4Vos1JPIaKtK/wwOUc 8LcQ== X-Forwarded-Encrypted: i=1; AJvYcCX63kWYSC0dxP75ODTTCK9tTuqucclryWq0AX1RKDwsp1pO1OBPdNqLKsyJfUb2OX7Ej2CQ6BjJJVvD@nongnu.org X-Gm-Message-State: AOJu0YwtDBWP8D75OibeGU4zIy+ITzmyUf7wl8d6aQNGbyR5rBJX2QAR WrbnoXDMNInfx51uG1oeh8w4jtFz+/WyHTjmsbOQiRzZe+qNe80vLS2B8A== X-Gm-Gg: ASbGnct1StQP0TEEBCtCXMFCFOcWrCeM62E7eI+tqWRmyxmuy2ktYUnLPIQWM7wvsGq ft8gZQVHFombVgiQERecvM1F9yGCIXd8iOUI1YuzKeXhqp4FVGDioluqCMK5uuU1l+kzQpmJk0s JUgc8N26B247hMJgIF3cdcbBG9EnVjriaHpLXZdr1S+tf7Zwjn3k2P6uRB22s8vbckAZuNlLC/7 TOYlwgGdJl1wyir0gMkwwLJf98ZvS2OxK0n1J7hGFT7ZMRsgVISLL8lvVkGb8h0fs6l0wd8xkOo fLYNLMsPAg== X-Google-Smtp-Source: AGHT+IH5eQF7myZlAt9nZCuaVN975lEjTetbEhkahQ07N+9tQX6lQiH999/pfejp/Ri7CRb1+Mp3iA== X-Received: by 2002:a17:902:e881:b0:216:2d42:2e05 with SMTP id d9443c01a7336-219d9672024mr33052425ad.22.1734579651416; Wed, 18 Dec 2024 19:40:51 -0800 (PST) Received: from wheely.local0.net (14-200-18-130.tpgi.com.au. [14.200.18.130]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc970520sm2881595ad.75.2024.12.18.19.40.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 19:40:51 -0800 (PST) From: Nicholas Piggin To: qemu-ppc@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , qemu-devel@nongnu.org Subject: [PATCH 3/5] spapr: Generate random HASHPKEYR for spapr machines Date: Thu, 19 Dec 2024 13:40:33 +1000 Message-ID: <20241219034035.1826173-4-npiggin@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241219034035.1826173-1-npiggin@gmail.com> References: <20241219034035.1826173-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=npiggin@gmail.com; helo=mail-pl1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The hypervisor is expected to create a value for the HASHPKEY SPR for each partition. Currently it uses zero for all partitions, use a random number instead, which in theory might make kernel ROP protection more secure. Signed-of-by: Nicholas Piggin Reviewed-by: Harsh Prateek Bora Reviewed-by: Philippe Mathieu-Daudé --- include/hw/ppc/spapr.h | 1 + hw/ppc/spapr.c | 3 +++ hw/ppc/spapr_cpu_core.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index af4aa1cb0fb..db44893689b 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -201,6 +201,7 @@ struct SpaprMachineState { uint32_t fdt_initial_size; void *fdt_blob; uint8_t fdt_rng_seed[32]; + uint64_t hashpkey_val; long kernel_size; bool kernel_le; uint64_t kernel_addr; diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index fa05e0c5156..34934afd551 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2888,6 +2888,9 @@ static void spapr_machine_init(MachineState *machine) spapr_ovec_set(spapr->ov5, OV5_XIVE_EXPLOIT); } + qemu_guest_getrandom_nofail(&spapr->hashpkey_val, + sizeof(spapr->hashpkey_val)); + /* init CPUs */ spapr_init_cpus(spapr); diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 88d743a3c3f..bf9f29f4ff3 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -273,6 +273,8 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr, env->spr_cb[SPR_PIR].default_value = cs->cpu_index; env->spr_cb[SPR_TIR].default_value = thread_index; + env->spr_cb[SPR_HASHPKEYR].default_value = spapr->hashpkey_val; + cpu_ppc_set_1lpar(cpu); /* Set time-base frequency to 512 MHz. vhyp must be set first. */ From patchwork Thu Dec 19 03:40:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13914438 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 7EE4DE7718B for ; Thu, 19 Dec 2024 03:42:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tO7PI-00076L-Ug; Wed, 18 Dec 2024 22:41:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tO7PF-00075T-UO; Wed, 18 Dec 2024 22:40:58 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tO7PE-0004Iv-B0; Wed, 18 Dec 2024 22:40:57 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-21683192bf9so3405345ad.3; Wed, 18 Dec 2024 19:40:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734579654; x=1735184454; darn=nongnu.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=Vwlpe1MB5sgsXYOFPBQEhsgxZTpLhzeJKWOWZzIcj+E=; b=db5PAK6hvpNrSUJ8WNibKh11xgdJvDq2G6dqYkJSC1tNvaGRmEW39HbNzWuNxn1I87 rtCwMrDdSC/Nl5fk10dpFycKqzvTsBPcE9Ezc7S3MeyzAtTKk+KyBCuMMJBLOQCZjNBA Li2w+ttDAyLn/l3SEBByuLw1yTcIIRN69qSLSiOpGYpwNVLLgOY7OmfnqNXuGb0sh6GP KQ99hHlwceR4gWJ5JPkES/NCDqM/hiIAzcb86mnaRX0py8YFV+a1Rjrd4/B0mnZ8v+XI 6uU7XuUszKD4q9tGoRzffRwGfIIGR0r6qz5/e5ByFeYR/wDoXVMp6usTb1XrtDYmDlmd jKtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734579654; x=1735184454; 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=Vwlpe1MB5sgsXYOFPBQEhsgxZTpLhzeJKWOWZzIcj+E=; b=QdcO2TWQa05wIvoYhx+Og9+lfD26s++pDom/+JaV3qqGIm/tasG/oEQnYOrpMSSNum 9zz+g/Nbe5bmrBSJeyPMBREZdePze6dbhOrNkVNcP44JgGQ8H53+t8Jauqww8ZLC4DGH 4WDvP4GHXpvtIr4dZ6HGDMDD8ufk6t08p3Tlh/7p5TyXWqC6wxSqryVAkezGlX3d4Hnm 7TFFbnwSijom3dAIu/LG5ciSw/R35e/83j2819VDFN6mahDpP0l5R0hua9HAm6MGQ8bd fsbb+yB+X8px+sGyNESI080qeoHXP1llIyt1FkGXymFez6GpbuhFb5Tx1iFWTlqbSh8f ryFw== X-Forwarded-Encrypted: i=1; AJvYcCX4gXP5bER6CJbhJc0dCnuxCDON4z44b4t0fYM1b+eVCcY7YZWrql731Ss2jtA2bVjiJDpBeRMjaryD@nongnu.org X-Gm-Message-State: AOJu0YwD3KAMxZfdetexD1SlPqUItmMDl33GUzbNYWtmMhwK3i47CLIa zLP6+6hSC4RUrlPDQpKxjDfaJNgva9oQlydi5yTIW2bbtoZwB+g/qn1aSQ== X-Gm-Gg: ASbGncs8TKuOMgrj4BKl8nZLC7yuPx9uvFurDlmhAdokc0NikaJ+11RLDXw3cAN1NgA 2KdMAPVn86kJUBXtvmCY2rdbP3FPOLhjjxdJOYa7eboGYkxICxGyrRMQbX8wftRIWUr4qi2RGlj vssQ0CyfNQiXwpbK1JDn2Rjv2QSpb9Xzyi2uK2mdKw6si1U2xDV8OfdvMpjyzgpeNEXsjMb5C4K h9mvpFXQMosvO8sM6Thkp+n+D7vI831ExqL4aF0Lw+lp8vH07vrPBm89IbzW9dpEniFmpSZzkcF 2nafm18n9Q== X-Google-Smtp-Source: AGHT+IH2M/jisU1OzVQI0W7JexlH48qVb/oF3O9VlP9AZCZ4bUIl3TvcYLglPfAnMi/z+IrdWz3N1A== X-Received: by 2002:a17:902:e741:b0:216:2dc4:50ab with SMTP id d9443c01a7336-218d6fd5f54mr65907225ad.2.1734579654338; Wed, 18 Dec 2024 19:40:54 -0800 (PST) Received: from wheely.local0.net (14-200-18-130.tpgi.com.au. [14.200.18.130]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc970520sm2881595ad.75.2024.12.18.19.40.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 19:40:54 -0800 (PST) From: Nicholas Piggin To: qemu-ppc@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , qemu-devel@nongnu.org Subject: [PATCH 4/5] target/ppc: Avoid warning message for zero process table entries Date: Thu, 19 Dec 2024 13:40:34 +1000 Message-ID: <20241219034035.1826173-5-npiggin@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241219034035.1826173-1-npiggin@gmail.com> References: <20241219034035.1826173-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=npiggin@gmail.com; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org A translation that encounters a process table entry that is zero is something that Linux does to cause certain kernel NULL pointer dereferences to fault. It is not itself a programming error, so avoid the guest error log. Signed-off-by: Nicholas Piggin --- target/ppc/mmu-radix64.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c index be7a45f2549..02099300358 100644 --- a/target/ppc/mmu-radix64.c +++ b/target/ppc/mmu-radix64.c @@ -571,6 +571,20 @@ static int ppc_radix64_process_scoped_xlate(PowerPCCPU *cpu, prtbe0 = ldq_phys(cs->as, h_raddr); } + /* + * Some Linux uses a zero process table entry in PID!=0 for kernel context + * without userspace in order to fault on NULL dereference, because using + * PIDR=0 for the kernel causes the Q0 page table to be used to translate + * Q3 as well. Check for that case here to avoid the invalid configuration + * message. + */ + if (unlikely(!prtbe0)) { + if (guest_visible) { + ppc_radix64_raise_si(cpu, access_type, eaddr, DSISR_R_BADCONFIG); + } + return 1; + } + /* Walk Radix Tree from Process Table Entry to Convert EA to RA */ *g_page_size = PRTBE_R_GET_RTS(prtbe0); base_addr = prtbe0 & PRTBE_R_RPDB; From patchwork Thu Dec 19 03:40:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13914435 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 1FB8EE77184 for ; Thu, 19 Dec 2024 03:41:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tO7PU-00077i-9A; Wed, 18 Dec 2024 22:41:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tO7PM-00076i-El; Wed, 18 Dec 2024 22:41:04 -0500 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tO7PH-0004JD-81; Wed, 18 Dec 2024 22:41:04 -0500 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-7fd49d85f82so184919a12.3; Wed, 18 Dec 2024 19:40:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734579657; x=1735184457; darn=nongnu.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=dH0e3/pZqO5cSRapQt3yCMopH0TKWEFkSF3QFzJFiLE=; b=ibY8tRH0x64xikGaqRFhewe1HfIR8LRyNyG8dx2Prh14oygF8Oj8Um+uf7XS65clV8 NIJHYVKWnGz+lg6FCatnZC6kCcmlXNtX9/zyG3/QoNNs+inR5Fwcjk3Y+o3ftsIh/Tms b5wn6b2QsISi4LKqGIcgcdLMGqy4RuZQ1Yfgbq2y6AjSrCk/hx7PePO/tqu4kT274gjL BjXyAOWnWI3Ts9s6SYgh7mi3II2h4og2qnBU9PM8vwVAZM/rmlH+TE++0aF8XTRR2tU7 FBZ9Y6MC16xj2SH5rB4gHkSMqiSGZQ2/pXb6oEUOn3Tm9qmxyXeDDhXp8gz+RTQebJSb biZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734579657; x=1735184457; 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=dH0e3/pZqO5cSRapQt3yCMopH0TKWEFkSF3QFzJFiLE=; b=bB1uOACURmwt8NfveagC4s0p0bw8aLtkBurnkk9plyrwsEbdQ0VqTvFTEhDFnDt1Fm WrYGESlHb5HepBZFcTz9Ol6UAGNzMhZgrPIarJD/pZoAU075Xm9ZtXQQNy6j+rFs57tz O+EAaPnEbIfrEekKF1k7MLG5NnRAKuXn8jM+H/3xgJW4lMpypk46Rx3VrDUsgYowccei gSg2+dYUx3uUm4XFx+Vfwradd10TuSJSXYjj5RFkZijGiOpsLVlan95L97fh87GHlB9K s1BBROCtrFT2GjsmcNDm0KhbO9vnubbOmmSFX2p+BEEG8ocP3Cqk5PJt6rAh0Pql9U1z GAYw== X-Forwarded-Encrypted: i=1; AJvYcCUOZs8GJ27DNti2wAddh32LIrPLH2dN53oeSBTMm0AUTIVc0dUVyQ8mWUQ+JCrf+mBVomgsUUtHivY4@nongnu.org X-Gm-Message-State: AOJu0YyR15PkcOL0FNl2VxQ1kEMaBD3T7vDUjevUCIw7aLK7I31HILm3 BqWbAmjmg1lBiLCYPtrxk3XCBd7bjAj7GWKHaGzKIMMF65YaW3efwphwfA== X-Gm-Gg: ASbGnctkKKKVm9+wWQRgvhHiwKbwKWxCM1JAvOczOcexCwdd0StQNJl0NYAJ1Cm5u7v icDqgIYKUdq7+hbqql6afH3nfjdR/4A1LgToJg453dvS9FnC/ifgt1nCmyBEFQdU4L3xG1oWSny sKj5OSzX2KreXKjWxFfJ9An4AVAzaqaCVmykHzPh2AmXBCrcGj0QcqZfzU8sqi1tjSU0PQm+I3o W4LE6yGhHr4VQnrJXKHMRtPV/9nv5azfugaRN3NGNr+KM6lUASdlf1wosUPbz0qLx/7j/AiTKSs Wa5noendUw== X-Google-Smtp-Source: AGHT+IF4F7xuIiB3HLAG4AJh4EeOoDe/9AIZQJAWe7c9SZj3c95DgHtuhbX1LEERG3D+53XZRg9AWA== X-Received: by 2002:a17:902:ea08:b0:215:2f00:67b1 with SMTP id d9443c01a7336-218d6fd4be7mr65976105ad.6.1734579657231; Wed, 18 Dec 2024 19:40:57 -0800 (PST) Received: from wheely.local0.net (14-200-18-130.tpgi.com.au. [14.200.18.130]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc970520sm2881595ad.75.2024.12.18.19.40.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 19:40:56 -0800 (PST) From: Nicholas Piggin To: qemu-ppc@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , qemu-devel@nongnu.org Subject: [PATCH 5/5] target/ppc: Wire up BookE ATB registers for e500 family Date: Thu, 19 Dec 2024 13:40:35 +1000 Message-ID: <20241219034035.1826173-6-npiggin@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241219034035.1826173-1-npiggin@gmail.com> References: <20241219034035.1826173-1-npiggin@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=npiggin@gmail.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From the Freescale PowerPC Architecture Primer: Alternate time base APU. This APU, implemented on the e500v2, defines a 64-bit time base counter that differs from the PowerPC defined time base in that it is not writable and counts at a different, and typically much higher, frequency. The alternate time base always counts up, wrapping when the 64-bit count overflows. This implementation of ATB uses the same frequency as the TB. The existing spr_read_atbu/l functions are unused without this patch to wire them into the SPR. RTEMS uses this SPR on the e6500, though this hasn't been tested. Signed-off-by: Nicholas Piggin --- target/ppc/cpu_init.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c index 1253dbf622c..4f0a64e7f99 100644 --- a/target/ppc/cpu_init.c +++ b/target/ppc/cpu_init.c @@ -922,6 +922,18 @@ static void register_BookE206_sprs(CPUPPCState *env, uint32_t mas_mask, #endif } +static void register_atb_sprs(CPUPPCState *env) +{ + spr_register(env, SPR_ATBL, "ATBL", + &spr_read_atbl, SPR_NOACCESS, + &spr_read_atbl, SPR_NOACCESS, + 0x00000000); + spr_register(env, SPR_ATBU, "ATBU", + &spr_read_atbu, SPR_NOACCESS, + &spr_read_atbu, SPR_NOACCESS, + 0x00000000); +} + /* SPR specific to PowerPC 440 implementation */ static void register_440_sprs(CPUPPCState *env) { @@ -2911,6 +2923,11 @@ static void init_proc_e500(CPUPPCState *env, int version) register_BookE206_sprs(env, 0x000000DF, tlbncfg, mmucfg); register_usprgh_sprs(env); + if (version != fsl_e500v1) { + /* e500v1 has no support for alternate timebase */ + register_atb_sprs(env); + } + spr_register(env, SPR_HID0, "HID0", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic,