From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631021880501636.5624677151217; Tue, 7 Sep 2021 06:38:00 -0700 (PDT) Received: from localhost ([::1]:33798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbIV-0001gY-Ds for importer@patchew.org; Tue, 07 Sep 2021 09:37:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawM-00035Q-70 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58297) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawK-0002Gr-C2 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:05 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-356-VMVo6Qy-N1WHysM4Dg0vxw-1; Tue, 07 Sep 2021 09:15:00 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 28FF2501E6; Tue, 7 Sep 2021 13:14:59 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9598F5C1B4; Tue, 7 Sep 2021 13:14:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xDiSpT8/0/iOgoA90CPNRSwuaTYy0g2zubuo4AaEDzI=; b=I7voZgvaFkEaPh55igx0mZlKViiHbzOpnEhCXFpMmc/sqQpHtoLRUeIBQFsufRmRbcRNIP FU9dc1fG8V02JZMbE1JtLswZf2Almb7ZSOJN674yjGrHGQtU0PWuvILHMzlcTKUdM4vfVu aJEGn2H5rjBQYPg9Qa64w/IAIiFEyB8= X-MC-Unique: VMVo6Qy-N1WHysM4Dg0vxw-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 01/20] vfio-ccw: forward halt/clear errors Date: Tue, 7 Sep 2021 15:14:30 +0200 Message-Id: <20210907131449.493875-2-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, Cornelia Huck , Jared Rossi , Matthew Rosato Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631021882704100001 Content-Type: text/plain; charset="utf-8" From: Cornelia Huck hsch and csch basically have two parts: execute the command, and perform the halt/clear function. For fully emulated subchannels, it is pretty clear how it will work: check the subchannel state, and actually 'perform the halt/clear function' and set cc 0 if everything looks good. For passthrough subchannels, some of the checking is done within QEMU, but some has to be done within the kernel. QEMU's subchannel state may be such that we can perform the async function, but the kernel may still get a cc !=3D 0 when it is actually executing the instruction. In that case, we need to set the condition actually encountered by the kernel; if we set cc 0 on error, we would actually need to inject an interrupt as well. Signed-off-by: Cornelia Huck Reviewed-by: Matthew Rosato Tested-by: Jared Rossi Message-Id: <20210705163952.736020-2-cohuck@redhat.com> Signed-off-by: Thomas Huth --- hw/s390x/css.c | 38 ++++++++++++++++++++++++++++++++++---- hw/vfio/ccw.c | 4 ++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/hw/s390x/css.c b/hw/s390x/css.c index 133ddea575..7d9523f811 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -1206,23 +1206,53 @@ static void sch_handle_start_func_virtual(SubchDev = *sch) =20 } =20 -static void sch_handle_halt_func_passthrough(SubchDev *sch) +static IOInstEnding sch_handle_halt_func_passthrough(SubchDev *sch) { int ret; =20 ret =3D s390_ccw_halt(sch); if (ret =3D=3D -ENOSYS) { sch_handle_halt_func(sch); + return IOINST_CC_EXPECTED; + } + /* + * Some conditions may have been detected prior to starting the halt + * function; map them to the correct cc. + * Note that we map both -ENODEV and -EACCES to cc 3 (there's not real= ly + * anything else we can do.) + */ + switch (ret) { + case -EBUSY: + return IOINST_CC_BUSY; + case -ENODEV: + case -EACCES: + return IOINST_CC_NOT_OPERATIONAL; + default: + return IOINST_CC_EXPECTED; } } =20 -static void sch_handle_clear_func_passthrough(SubchDev *sch) +static IOInstEnding sch_handle_clear_func_passthrough(SubchDev *sch) { int ret; =20 ret =3D s390_ccw_clear(sch); if (ret =3D=3D -ENOSYS) { sch_handle_clear_func(sch); + return IOINST_CC_EXPECTED; + } + /* + * Some conditions may have been detected prior to starting the clear + * function; map them to the correct cc. + * Note that we map both -ENODEV and -EACCES to cc 3 (there's not real= ly + * anything else we can do.) + */ + switch (ret) { + case -ENODEV: + case -EACCES: + return IOINST_CC_NOT_OPERATIONAL; + default: + return IOINST_CC_EXPECTED; } } =20 @@ -1265,9 +1295,9 @@ IOInstEnding do_subchannel_work_passthrough(SubchDev = *sch) SCHIB *schib =3D &sch->curr_status; =20 if (schib->scsw.ctrl & SCSW_FCTL_CLEAR_FUNC) { - sch_handle_clear_func_passthrough(sch); + return sch_handle_clear_func_passthrough(sch); } else if (schib->scsw.ctrl & SCSW_FCTL_HALT_FUNC) { - sch_handle_halt_func_passthrough(sch); + return sch_handle_halt_func_passthrough(sch); } else if (schib->scsw.ctrl & SCSW_FCTL_START_FUNC) { return sch_handle_start_func_passthrough(sch); } diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 000992fb9f..0354737666 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -199,7 +199,7 @@ again: case 0: case -ENODEV: case -EACCES: - return 0; + return ret; case -EFAULT: default: sch_gen_unit_exception(sch); @@ -240,7 +240,7 @@ again: case -EBUSY: case -ENODEV: case -EACCES: - return 0; + return ret; case -EFAULT: default: sch_gen_unit_exception(sch); --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631022037894703.2488109707978; Tue, 7 Sep 2021 06:40:37 -0700 (PDT) Received: from localhost ([::1]:41130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbL2-0006no-SO for importer@patchew.org; Tue, 07 Sep 2021 09:40:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawQ-00037l-3b for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawO-0002J5-MV for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:09 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-64-J03p1ZMxNyqIg84QPlKlmg-1; Tue, 07 Sep 2021 09:15:04 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 283F5802935; Tue, 7 Sep 2021 13:15:03 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 885555C1B4; Tue, 7 Sep 2021 13:14:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020508; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=92eyOB5Uo2QNQSlgVUBo0CzXNg/TVspDu1k/Apuos2c=; b=WKaVj02C5cnHiw024YTdkuNmoJxKa4kW6WH/Rl2RcZL01QXKFBYUOt1NXM5JeC8KPiKjhv iJiXUIfe9fPnuXZxny7tZu4rEt7VeHhgUOjIu4ZdgWDjFphfjCFrmULfwQkJpxlxfazl9+ N/nfxyOMol/ZiU9PgWc6N33wQ0b2onw= X-MC-Unique: J03p1ZMxNyqIg84QPlKlmg-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 02/20] css: fix actl handling for unit exceptions Date: Tue, 7 Sep 2021 15:14:31 +0200 Message-Id: <20210907131449.493875-3-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, Cornelia Huck , Jared Rossi , Matthew Rosato Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631022039769100003 Content-Type: text/plain; charset="utf-8" From: Cornelia Huck When a subchannel becomes pending with unit exception, start pending (and for that matter, halt or clear pending) are not removed in the actl. Device active and subchannel active, however, are (due to the subchannel becoming status pending with primary respectively secondary status). The other conditions in the actl are only cleared when the guest executes tsch on the subchannel. Signed-off-by: Cornelia Huck Reviewed-by: Matthew Rosato Tested-by: Jared Rossi Message-Id: <20210705163952.736020-3-cohuck@redhat.com> Signed-off-by: Thomas Huth --- include/hw/s390x/css.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index 10ed1df1bb..75e5381613 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -146,7 +146,8 @@ struct SubchDev { =20 static inline void sch_gen_unit_exception(SubchDev *sch) { - sch->curr_status.scsw.ctrl &=3D ~SCSW_ACTL_START_PEND; + sch->curr_status.scsw.ctrl &=3D ~(SCSW_ACTL_DEVICE_ACTIVE | + SCSW_ACTL_SUBCH_ACTIVE); sch->curr_status.scsw.ctrl |=3D SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | SCSW_STCTL_ALERT | --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631021744830161.07170092219337; Tue, 7 Sep 2021 06:35:44 -0700 (PDT) Received: from localhost ([::1]:54440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbGJ-0004ng-Mz for importer@patchew.org; Tue, 07 Sep 2021 09:35:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawe-0003Ch-Oz for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45136) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawV-0002L6-OB for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-109-LRZ3_RmvNo2FaEbJ57rzbA-1; Tue, 07 Sep 2021 09:15:11 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 51D7B1013720; Tue, 7 Sep 2021 13:15:10 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F6965FC25; Tue, 7 Sep 2021 13:15:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Git4jmxTBvGfii58Z4QIjJbK9sKyH/5Jhvau5kWvnjQ=; b=FoW7tpgreLTTzaVaQdwL7XKIgnRF94f5d2qdYJEG331A5nBdQNeuoUoWiBFl2X97LlSsO5 bwDv/4yPNThUEelRoAfA0/NypYACQOB3C7vFiCBTP6Q1bQyD50f4xjPpG8bPqZykeAxrqp ol62ZrTMWOlt+9PXWqbLh6o8nkUEsdc= X-MC-Unique: LRZ3_RmvNo2FaEbJ57rzbA-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 03/20] tests/tcg/s390x: Test SIGILL and SIGSEGV handling Date: Tue, 7 Sep 2021 15:14:32 +0200 Message-Id: <20210907131449.493875-4-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, Cornelia Huck , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Ilya Leoshkevich , David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631021745214100001 From: Ilya Leoshkevich Verify that s390x-specific uc_mcontext.psw.addr is reported correctly and that signal handling interacts properly with debugging. Signed-off-by: Ilya Leoshkevich Acked-by: Alex Benn=C3=A9e Acked-by: David Hildenbrand Message-Id: <20210804225146.154513-1-iii@linux.ibm.com> Signed-off-by: Cornelia Huck Signed-off-by: Thomas Huth --- tests/tcg/s390x/Makefile.target | 17 +- tests/tcg/s390x/gdbstub/test-signals-s390x.py | 76 ++++++++ tests/tcg/s390x/signals-s390x.c | 165 ++++++++++++++++++ 3 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/s390x/gdbstub/test-signals-s390x.py create mode 100644 tests/tcg/s390x/signals-s390x.c diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.tar= get index bd084c7840..cc64dd32d2 100644 --- a/tests/tcg/s390x/Makefile.target +++ b/tests/tcg/s390x/Makefile.target @@ -1,4 +1,5 @@ -VPATH+=3D$(SRC_PATH)/tests/tcg/s390x +S390X_SRC=3D$(SRC_PATH)/tests/tcg/s390x +VPATH+=3D$(S390X_SRC) CFLAGS+=3D-march=3DzEC12 -m64 TESTS+=3Dhello-s390x TESTS+=3Dcsst @@ -9,3 +10,17 @@ TESTS+=3Dpack TESTS+=3Dmvo TESTS+=3Dmvc TESTS+=3Dtrap +TESTS+=3Dsignals-s390x + +ifneq ($(HAVE_GDB_BIN),) +GDB_SCRIPT=3D$(SRC_PATH)/tests/guest-debug/run-test.py + +run-gdbstub-signals-s390x: signals-s390x + $(call run-test, $@, $(GDB_SCRIPT) \ + --gdb $(HAVE_GDB_BIN) \ + --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ + --bin $< --test $(S390X_SRC)/gdbstub/test-signals-s390x.py, \ + "mixing signals and debugging on s390x") + +EXTRA_RUNS +=3D run-gdbstub-signals-s390x +endif diff --git a/tests/tcg/s390x/gdbstub/test-signals-s390x.py b/tests/tcg/s390= x/gdbstub/test-signals-s390x.py new file mode 100644 index 0000000000..80a284b475 --- /dev/null +++ b/tests/tcg/s390x/gdbstub/test-signals-s390x.py @@ -0,0 +1,76 @@ +from __future__ import print_function + +# +# Test that signals and debugging mix well together on s390x. +# +# This is launched via tests/guest-debug/run-test.py +# + +import gdb +import sys + +failcount =3D 0 + + +def report(cond, msg): + """Report success/fail of test""" + if cond: + print("PASS: %s" % (msg)) + else: + print("FAIL: %s" % (msg)) + global failcount + failcount +=3D 1 + + +def run_test(): + """Run through the tests one by one""" + illegal_op =3D gdb.Breakpoint("illegal_op") + stg =3D gdb.Breakpoint("stg") + mvc_8 =3D gdb.Breakpoint("mvc_8") + + # Expect the following events: + # 1x illegal_op breakpoint + # 2x stg breakpoint, segv, breakpoint + # 2x mvc_8 breakpoint, segv, breakpoint + for _ in range(14): + gdb.execute("c") + report(illegal_op.hit_count =3D=3D 1, "illegal_op.hit_count =3D=3D 1") + report(stg.hit_count =3D=3D 4, "stg.hit_count =3D=3D 4") + report(mvc_8.hit_count =3D=3D 4, "mvc_8.hit_count =3D=3D 4") + + # The test must succeed. + gdb.Breakpoint("_exit") + gdb.execute("c") + status =3D int(gdb.parse_and_eval("$r2")) + report(status =3D=3D 0, "status =3D=3D 0"); + + +# +# This runs as the script it sourced (via -x, via run-test.py) +# +try: + inferior =3D gdb.selected_inferior() + arch =3D inferior.architecture() + print("ATTACHED: %s" % arch.name()) +except (gdb.error, AttributeError): + print("SKIPPING (not connected)", file=3Dsys.stderr) + exit(0) + +if gdb.parse_and_eval("$pc") =3D=3D 0: + print("SKIP: PC not set") + exit(0) + +try: + # These are not very useful in scripts + gdb.execute("set pagination off") + gdb.execute("set confirm off") + + # Run the actual tests + run_test() +except (gdb.error): + print("GDB Exception: %s" % (sys.exc_info()[0])) + failcount +=3D 1 + pass + +print("All tests complete: %d failures" % failcount) +exit(failcount) diff --git a/tests/tcg/s390x/signals-s390x.c b/tests/tcg/s390x/signals-s390= x.c new file mode 100644 index 0000000000..dc2f8ee59a --- /dev/null +++ b/tests/tcg/s390x/signals-s390x.c @@ -0,0 +1,165 @@ +#include +#include +#include +#include +#include +#include + +/* + * Various instructions that generate SIGILL and SIGSEGV. They could have = been + * defined in a separate .s file, but this would complicate the build, so = the + * inline asm is used instead. + */ + +void illegal_op(void); +void after_illegal_op(void); +asm(".globl\tillegal_op\n" + "illegal_op:\t.byte\t0x00,0x00\n" + "\t.globl\tafter_illegal_op\n" + "after_illegal_op:\tbr\t%r14"); + +void stg(void *dst, unsigned long src); +asm(".globl\tstg\n" + "stg:\tstg\t%r3,0(%r2)\n" + "\tbr\t%r14"); + +void mvc_8(void *dst, void *src); +asm(".globl\tmvc_8\n" + "mvc_8:\tmvc\t0(8,%r2),0(%r3)\n" + "\tbr\t%r14"); + +static void safe_puts(const char *s) +{ + write(0, s, strlen(s)); + write(0, "\n", 1); +} + +enum exception { + exception_operation, + exception_translation, + exception_protection, +}; + +static struct { + int sig; + void *addr; + unsigned long psw_addr; + enum exception exception; +} expected; + +static void handle_signal(int sig, siginfo_t *info, void *ucontext) +{ + void *page; + int err; + + if (sig !=3D expected.sig) { + safe_puts("[ FAILED ] wrong signal"); + _exit(1); + } + + if (info->si_addr !=3D expected.addr) { + safe_puts("[ FAILED ] wrong si_addr"); + _exit(1); + } + + if (((ucontext_t *)ucontext)->uc_mcontext.psw.addr !=3D expected.psw_a= ddr) { + safe_puts("[ FAILED ] wrong psw.addr"); + _exit(1); + } + + switch (expected.exception) { + case exception_translation: + page =3D mmap(expected.addr, 4096, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); + if (page !=3D expected.addr) { + safe_puts("[ FAILED ] mmap() failed"); + _exit(1); + } + break; + case exception_protection: + err =3D mprotect(expected.addr, 4096, PROT_READ | PROT_WRITE); + if (err !=3D 0) { + safe_puts("[ FAILED ] mprotect() failed"); + _exit(1); + } + break; + default: + break; + } +} + +static void check_sigsegv(void *func, enum exception exception, + unsigned long val) +{ + int prot; + unsigned long *page; + unsigned long *addr; + int err; + + prot =3D exception =3D=3D exception_translation ? PROT_NONE : PROT_REA= D; + page =3D mmap(NULL, 4096, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + assert(page !=3D MAP_FAILED); + if (exception =3D=3D exception_translation) { + /* Hopefully nothing will be mapped at this address. */ + err =3D munmap(page, 4096); + assert(err =3D=3D 0); + } + addr =3D page + (val & 0x1ff); + + expected.sig =3D SIGSEGV; + expected.addr =3D page; + expected.psw_addr =3D (unsigned long)func; + expected.exception =3D exception; + if (func =3D=3D stg) { + stg(addr, val); + } else { + assert(func =3D=3D mvc_8); + mvc_8(addr, &val); + } + assert(*addr =3D=3D val); + + err =3D munmap(page, 4096); + assert(err =3D=3D 0); +} + +int main(void) +{ + struct sigaction act; + int err; + + memset(&act, 0, sizeof(act)); + act.sa_sigaction =3D handle_signal; + act.sa_flags =3D SA_SIGINFO; + err =3D sigaction(SIGILL, &act, NULL); + assert(err =3D=3D 0); + err =3D sigaction(SIGSEGV, &act, NULL); + assert(err =3D=3D 0); + + safe_puts("[ RUN ] Operation exception"); + expected.sig =3D SIGILL; + expected.addr =3D illegal_op; + expected.psw_addr =3D (unsigned long)after_illegal_op; + expected.exception =3D exception_operation; + illegal_op(); + safe_puts("[ OK ]"); + + safe_puts("[ RUN ] Translation exception from stg"); + check_sigsegv(stg, exception_translation, 42); + safe_puts("[ OK ]"); + + safe_puts("[ RUN ] Translation exception from mvc"); + check_sigsegv(mvc_8, exception_translation, 4242); + safe_puts("[ OK ]"); + + safe_puts("[ RUN ] Protection exception from stg"); + check_sigsegv(stg, exception_protection, 424242); + safe_puts("[ OK ]"); + + safe_puts("[ RUN ] Protection exception from mvc"); + check_sigsegv(mvc_8, exception_protection, 42424242); + safe_puts("[ OK ]"); + + safe_puts("[ PASSED ]"); + + _exit(0); +} --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631022136045814.9355298406617; Tue, 7 Sep 2021 06:42:16 -0700 (PDT) Received: from localhost ([::1]:48108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbMd-0003JA-3F for importer@patchew.org; Tue, 07 Sep 2021 09:42:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawq-0003JQ-Tr for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43333) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawk-0002Og-59 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:36 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-490-xL_MfVJIMK-SJ8G5iy45Yg-1; Tue, 07 Sep 2021 09:15:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D94756BA1; Tue, 7 Sep 2021 13:15:16 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id A115E17258; Tue, 7 Sep 2021 13:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020518; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DdTkyxxjgv5UIAzXmWlWzTbdsYCe4ltA3Qjx5VEJ/ro=; b=a63dA+h/1ayMSMiz9fgHuKNz/3PKm+aSLFWY7Bvh74GlKX3j0pudaLn4yEd8uxCxgUNuf0 wzjESHIX7zfRio2bdwTsqGGfu/Au31woWwRTpUOkL+UVzMhHCr/K7TQ22ZeKGcDTuX/Gh0 iGrbuQaB13RzihwlNgAZ6wacPPLnv4Q= X-MC-Unique: xL_MfVJIMK-SJ8G5iy45Yg-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 04/20] s390x/tcg: fix and optimize SPX (SET PREFIX) Date: Tue, 7 Sep 2021 15:14:33 +0200 Message-Id: <20210907131449.493875-5-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Claudio Imbrenda , qemu-s390x@nongnu.org, Cornelia Huck , Richard Henderson , David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631022137768100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand We not only invalidate the translation of the range 0x0-0x2000, we also invalidate the translation of the new prefix range and the translation of the old prefix range -- because real2abs would return different results for all of these ranges when changing the prefix location. This fixes the kvm-unit-tests "edat" test that just hangs before this patch because we end up clearing the new prefix area instead of the old prefix area. While at it, let's not do anything in case the prefix doesn't change. Cc: Richard Henderson Cc: David Hildenbrand Cc: Cornelia Huck Cc: Thomas Huth Cc: Claudio Imbrenda Cc: qemu-s390x@nongnu.org Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth Reviewed-by: Claudio Imbrenda Message-Id: <20210805125938.74034-1-david@redhat.com> Signed-off-by: Cornelia Huck Signed-off-by: Thomas Huth --- target/s390x/tcg/misc_helper.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/target/s390x/tcg/misc_helper.c b/target/s390x/tcg/misc_helper.c index 33e6999e15..aab9c47747 100644 --- a/target/s390x/tcg/misc_helper.c +++ b/target/s390x/tcg/misc_helper.c @@ -151,13 +151,26 @@ void HELPER(diag)(CPUS390XState *env, uint32_t r1, ui= nt32_t r3, uint32_t num) /* Set Prefix */ void HELPER(spx)(CPUS390XState *env, uint64_t a1) { + const uint32_t prefix =3D a1 & 0x7fffe000; + const uint32_t old_prefix =3D env->psa; CPUState *cs =3D env_cpu(env); - uint32_t prefix =3D a1 & 0x7fffe000; + + if (prefix =3D=3D old_prefix) { + return; + } =20 env->psa =3D prefix; HELPER_LOG("prefix: %#x\n", prefix); tlb_flush_page(cs, 0); tlb_flush_page(cs, TARGET_PAGE_SIZE); + if (prefix !=3D 0) { + tlb_flush_page(cs, prefix); + tlb_flush_page(cs, prefix + TARGET_PAGE_SIZE); + } + if (old_prefix !=3D 0) { + tlb_flush_page(cs, old_prefix); + tlb_flush_page(cs, old_prefix + TARGET_PAGE_SIZE); + } } =20 static void update_ckc_timer(CPUS390XState *env) --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631021868610419.1421802403098; Tue, 7 Sep 2021 06:37:48 -0700 (PDT) Received: from localhost ([::1]:32786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbIJ-00010q-HA for importer@patchew.org; Tue, 07 Sep 2021 09:37:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawl-0003Ea-0L for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36948) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawi-0002TZ-Ez for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:30 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-101-rtiH7xaHPzuRvtAi9HCBPw-1; Tue, 07 Sep 2021 09:15:20 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 064D9189945C; Tue, 7 Sep 2021 13:15:19 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA25C5C1B4; Tue, 7 Sep 2021 13:15:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020523; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rj3Nbx5V1HdoTGWwlhTYv0zfPbm983M0dE7M4hY0xqc=; b=UAIddnbdwN2PHFcPqg7nfDCisAI+ZFQTl7NobleIihIIA2lkOYNIoef+oZvqxkBGi0XXD9 7UD/k7hJjkXbNxMsy4aRK5T3/d02ia98N1TMLBrluZMFcbmEb6fZAddq/s7oWnHxstEA1r CFgkMupSPloPf/yFHmxW50TzXqbxNpc= X-MC-Unique: rtiH7xaHPzuRvtAi9HCBPw-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 05/20] s390x/ioinst: Fix wrong MSCH alignment check on little endian Date: Tue, 7 Sep 2021 15:14:34 +0200 Message-Id: <20210907131449.493875-6-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pierre Morel , David Hildenbrand , Cornelia Huck , Richard Henderson , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631021870716100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand schib->pmcw.chars is 32bit, not 16bit. This fixes the kvm-unit-tests "css" test, which fails with: FAIL: Channel Subsystem: measurement block format1: Unaligned MB origin: Program interrupt: expected(21) =3D=3D received(0) Because we end up not injecting an operand program exception. Fixes: a54b8ac340c2 ("css: SCHIB measurement block origin must be aligned") Cc: Halil Pasic Cc: Cornelia Huck Cc: Christian Borntraeger Cc: Richard Henderson Cc: Thomas Huth Cc: Pierre Morel Cc: qemu-s390x@nongnu.org Signed-off-by: David Hildenbrand Reviewed-by: Halil Pasic Reviewed-by: Thomas Huth Reviewed-by: Pierre Morel Message-Id: <20210805143753.86520-1-david@redhat.com> Signed-off-by: Cornelia Huck Signed-off-by: Thomas Huth --- target/s390x/ioinst.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/s390x/ioinst.c b/target/s390x/ioinst.c index 4eb0a7a9f8..bdae5090bc 100644 --- a/target/s390x/ioinst.c +++ b/target/s390x/ioinst.c @@ -123,7 +123,7 @@ static int ioinst_schib_valid(SCHIB *schib) } /* for MB format 1 bits 26-31 of word 11 must be 0 */ /* MBA uses words 10 and 11, it means align on 2**6 */ - if ((be16_to_cpu(schib->pmcw.chars) & PMCW_CHARS_MASK_MBFC) && + if ((be32_to_cpu(schib->pmcw.chars) & PMCW_CHARS_MASK_MBFC) && (be64_to_cpu(schib->mba) & 0x03fUL)) { return 0; } --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631022318; cv=none; d=zohomail.com; s=zohoarc; b=eu/wEGXRtqAMq5GEB/md7gid7H6YIzn3Itjd1zWytLZKW/cJr7CC2BTMtifPYD9XVhdrYydEH/MbiPAglhb7KpIRW7JIcIs+3/VJpe/0urZh6sav7EVMWrQJHIjalMPUL/5y60Vbku1Dm0qzV0dt408luFNSiDMUze/AJ3SI8pE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631022318; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IvV6nEVbiIc1PJLQDa/7CVFhHsA7w/2ifB/3BOUZ6b0=; b=f+c/CSacT6ReMyUh0p/jh5c7ARiDvfOGCUlxHNXn3UZ7heHbb+7IV/GnR/5FBxLrWKJUpMPXklmKDXiksW0vHfxP1ad8TgmOLZgeMZ0B333wf4s7EnTBl42Ct726qpYADViodHffp2AiN/Wlkl/YCSzK2VLhfQG7bIusWtW5ccY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631022318791489.25980573013476; Tue, 7 Sep 2021 06:45:18 -0700 (PDT) Received: from localhost ([::1]:56654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbPZ-0000kk-FY for importer@patchew.org; Tue, 07 Sep 2021 09:45:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38302) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawp-0003HY-6W for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53431) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawl-0002Ud-Ig for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:34 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-96-J5wLMFHqPKSv1zWUz4xgrg-1; Tue, 07 Sep 2021 09:15:21 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9C52107ACED; Tue, 7 Sep 2021 13:15:20 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67B8D5C1B4; Tue, 7 Sep 2021 13:15:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020525; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IvV6nEVbiIc1PJLQDa/7CVFhHsA7w/2ifB/3BOUZ6b0=; b=L4BkRdJIkBoIbSs661W1D1hHPH4nmm0AlmaOMwDUI/qhYj9jAQp/4SClf7gKgKscwaVihv SSJp6zd2y8oPUjIM6pJ/42fWTvAzvGDSVRBZnl515uu4Ox9FM4CQSpZqR+a7L2k00DPD2I /WM5QEMsX+1Ob1ye0u9gWYJHIWB4+cA= X-MC-Unique: J5wLMFHqPKSv1zWUz4xgrg-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 06/20] s390x/tcg: wrap address for RRBE Date: Tue, 7 Sep 2021 15:14:35 +0200 Message-Id: <20210907131449.493875-7-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631022321215100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Let's wrap the address just like for SSKE and ISKE. Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth Message-Id: <20210903155514.44772-2-david@redhat.com> Signed-off-by: Thomas Huth --- target/s390x/tcg/mem_helper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c index 21a4de4067..e0befd0f03 100644 --- a/target/s390x/tcg/mem_helper.c +++ b/target/s390x/tcg/mem_helper.c @@ -2223,11 +2223,12 @@ void HELPER(sske)(CPUS390XState *env, uint64_t r1, = uint64_t r2) uint32_t HELPER(rrbe)(CPUS390XState *env, uint64_t r2) { MachineState *ms =3D MACHINE(qdev_get_machine()); + uint64_t addr =3D wrap_address(env, r2); static S390SKeysState *ss; static S390SKeysClass *skeyclass; uint8_t re, key; =20 - if (r2 > ms->ram_size) { + if (addr > ms->ram_size) { return 0; } =20 @@ -2236,14 +2237,14 @@ uint32_t HELPER(rrbe)(CPUS390XState *env, uint64_t = r2) skeyclass =3D S390_SKEYS_GET_CLASS(ss); } =20 - if (skeyclass->get_skeys(ss, r2 / TARGET_PAGE_SIZE, 1, &key)) { + if (skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key)) { return 0; } =20 re =3D key & (SK_R | SK_C); key &=3D ~SK_R; =20 - if (skeyclass->set_skeys(ss, r2 / TARGET_PAGE_SIZE, 1, &key)) { + if (skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key)) { return 0; } /* --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631022150; cv=none; d=zohomail.com; s=zohoarc; b=hWQ8tw5BgjPnX81sV1a8lMHAUYDdegORQDnmX4FMPy9GOZmUbaCnY65IweQhyged9uB1UKdII2nWp9lEceX+0dNe0k9JSLG+8ADKO884O5xrKgN+htOno+ITzZeXBM/AXbmVyTAwK+FpotycUTs/K9jxfKgt777EVjBlM/DmR0k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631022150; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y7N6AQ417MJMyaWkgC2RJARSP6QhDNnRj0oh3Q5s/r4=; b=EcWPDxtPyqQN4kj7dRzy9Me1sEF4JdmDukf59asqJdnMY9hmTcbCvgTrqbkN1cVbKt/n3pahIp2ZOgap8zEvdjRmB9vlG75ZE+2Fe8PJlaB0dFvJvXrGuA8UEWhx+W4aa3g6uzKZBqgkCl3N8/JvA68lqnJT2JsPOFS1VB0IZEg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631022150959439.15424963065027; Tue, 7 Sep 2021 06:42:30 -0700 (PDT) Received: from localhost ([::1]:49546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbMr-0004HT-Vr for importer@patchew.org; Tue, 07 Sep 2021 09:42:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawo-0003HW-JR for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46589) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawk-0002UG-52 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:34 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-538-TziVd-TRMAablIVvH0bVLg-1; Tue, 07 Sep 2021 09:15:23 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3E15C107ACCA; Tue, 7 Sep 2021 13:15:22 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F0395C25D; Tue, 7 Sep 2021 13:15:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y7N6AQ417MJMyaWkgC2RJARSP6QhDNnRj0oh3Q5s/r4=; b=B8BYoy3pjlRuEu4u4y/mW2ea8XQPzBvP69wmimBvz0w69WWw62M28YzCGHULusmpASRDuR /S+PBvxFJryDzcdyN6HR6TB5bEXQHY5M9Yk309+eHTKvvQITRxMpQhIqEcqJE31oel5wWV 23Ox2AOPe8s9jUuKGswTQOceU+rU2Rs= X-MC-Unique: TziVd-TRMAablIVvH0bVLg-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 07/20] s390x/tcg: fix ignoring bit 63 when setting the storage key in SSKE Date: Tue, 7 Sep 2021 15:14:36 +0200 Message-Id: <20210907131449.493875-8-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631022151583100003 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Right now we could set an 8-bit storage key via SSKE and retrieve it again via ISKE, which is against the architecture description: SSKE: " The new seven-bit storage-key value, or selected bits thereof, is obtained from bit positions 56-62 of gen- eral register R 1 . The contents of bit positions 0-55 and 63 of the register are ignored. " ISKE: " The seven-bit storage key is inserted in bit positions 56-62 of general register R 1 , and bit 63 is set to zero. " Let's properly ignore bit 63 to create the correct seven-bit storage key. Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth Message-Id: <20210903155514.44772-3-david@redhat.com> Signed-off-by: Thomas Huth --- target/s390x/tcg/mem_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c index e0befd0f03..3c0820dd74 100644 --- a/target/s390x/tcg/mem_helper.c +++ b/target/s390x/tcg/mem_helper.c @@ -2210,7 +2210,7 @@ void HELPER(sske)(CPUS390XState *env, uint64_t r1, ui= nt64_t r2) skeyclass =3D S390_SKEYS_GET_CLASS(ss); } =20 - key =3D (uint8_t) r1; + key =3D r1 & 0xfe; skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); /* * As we can only flush by virtual address and not all the entries --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631022016; cv=none; d=zohomail.com; s=zohoarc; b=JaoGQV4GYCkEeBvi3+e/J5LFiq4Ks2SDh3oIuTxceAQSQgao1uTwCRKuZ8hobuNS3jHr4WqOFjbOS5AwsMHxS2/8wQJHTd9SMCsxls1pHkG1r6wrEO13XqVFSXvSO0pLh+m2bMWPrDmBfJd6A5lRARXF2S+3iWuUhbqTrF8NusA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631022016; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pgxDINm2GHEMZcqKoxv3s7LaM40WtOIzvvw9zQeKW0E=; b=l0lHxnKxuT2GS7dm3i+R6ZMIP0bG6inCGcfbOKpIAP4u8PLuS9vFpFVmEUJTepwlgh+AsmyqJLsGdxFyUcJUVsWda3XWMfugmHdONXXxplVjnPe4mzWnZ0k/qQN3+GCEL/qqKWy06dSZRA8c3xi6cPQp37nUMrPAnQufQXBYO1A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631022016439531.5405291536391; Tue, 7 Sep 2021 06:40:16 -0700 (PDT) Received: from localhost ([::1]:39834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbKh-0005un-5C for importer@patchew.org; Tue, 07 Sep 2021 09:40:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawm-0003GI-Sb for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52887) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawi-0002Ul-FA for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:32 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-373-5n07UVy-NmevGgOsGZlESw-1; Tue, 07 Sep 2021 09:15:24 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4A97102CB6F; Tue, 7 Sep 2021 13:15:23 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D62E5C1B4; Tue, 7 Sep 2021 13:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pgxDINm2GHEMZcqKoxv3s7LaM40WtOIzvvw9zQeKW0E=; b=ftZgihfBbKIj6j0UKiL1ngudWn1qlYcY0plSMghr+HBMPLewhRjBSysnx3aCrMwSNC1tln VknsLG+8nKbH490KEYiDofYVrXRvWfIlIjjXgVyqSfMaJ43TaICKUsEPsPnfEF5MF82pNR +Zyt/JH5yg/mL3OK0FsWRni5xdI1XC8= X-MC-Unique: 5n07UVy-NmevGgOsGZlESw-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 08/20] s390x/tcg: convert real to absolute address for RRBE, SSKE and ISKE Date: Tue, 7 Sep 2021 15:14:37 +0200 Message-Id: <20210907131449.493875-9-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631022017102100003 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand For RRBE, SSKE, and ISKE, we're dealing with real addresses, so we have to convert to an absolute address first. In the future, when adding EDAT1 support, we'll have to pay attention to SSKE handling, as we'll be dealing with absolute addresses when the multiple-block control is one. Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth Message-Id: <20210903155514.44772-4-david@redhat.com> Signed-off-by: Thomas Huth --- target/s390x/tcg/mem_helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c index 3c0820dd74..dd506d8d17 100644 --- a/target/s390x/tcg/mem_helper.c +++ b/target/s390x/tcg/mem_helper.c @@ -2177,6 +2177,7 @@ uint64_t HELPER(iske)(CPUS390XState *env, uint64_t r2) uint64_t addr =3D wrap_address(env, r2); uint8_t key; =20 + addr =3D mmu_real2abs(env, addr); if (addr > ms->ram_size) { return 0; } @@ -2201,6 +2202,7 @@ void HELPER(sske)(CPUS390XState *env, uint64_t r1, ui= nt64_t r2) uint64_t addr =3D wrap_address(env, r2); uint8_t key; =20 + addr =3D mmu_real2abs(env, addr); if (addr > ms->ram_size) { return; } @@ -2228,6 +2230,7 @@ uint32_t HELPER(rrbe)(CPUS390XState *env, uint64_t r2) static S390SKeysClass *skeyclass; uint8_t re, key; =20 + addr =3D mmu_real2abs(env, addr); if (addr > ms->ram_size) { return 0; } --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631021847; cv=none; d=zohomail.com; s=zohoarc; b=log4UeyCZ/24BcjXefviqd78VsTZhdIu3yinY7WrD9e/ksD+YHfFuARxEn1gLHfU8zlL2vv23GMOzKxEx178DyeL4gcWjXnMcrgpfWCyQI3fffl0wfBQpOSexDloQDq9eejIgsfvU1k0+63kZ3TAHM+zHRhc+jHl3oaUgspE5d8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631021847; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZYk0txgp03tmyb/CJgfvtXHCsxvXFmFn6ON8tiHgF5I=; b=blggSnxYLWW9g+trILnphFgjlvXyfvJSPHM7GK9LDq2dbEfsJeA5EHOy94N0qxsl42ilXHq474kj2WNt9WvukcGyOmE5VKN+WJq4u7P9LjanzclT6l7ZYXndG4OQ0MnAIYLxUE1sRbt1IWlGu2Bv9zfLXm6HZwY3qZOtMw8u4r0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631021847536345.84300557088534; Tue, 7 Sep 2021 06:37:27 -0700 (PDT) Received: from localhost ([::1]:59460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbHy-0008Ng-Ce for importer@patchew.org; Tue, 07 Sep 2021 09:37:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawn-0003HG-Tx for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56319) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawk-0002V8-4r for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:33 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-266-R3C73lUVPWi1MbNYivU_Pw-1; Tue, 07 Sep 2021 09:15:26 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5EDEF802935; Tue, 7 Sep 2021 13:15:25 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1ED895C1B4; Tue, 7 Sep 2021 13:15:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020527; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZYk0txgp03tmyb/CJgfvtXHCsxvXFmFn6ON8tiHgF5I=; b=OFfN+ACQxqc0Lfo2+QkvRJEES1JQabegLSTDf2FPfXu69DThtZe5Kv4IaH/4O+6n44HQnz mJlu+hyjvhwqyCq3UCnCAfBOBjr3foDO3tcjFdRJj0YtbkOV19V/1a2LiVA4QvO7VbJJ9u 60Y5jlzA/FnD+YifijLGtKehXbsqP24= X-MC-Unique: R3C73lUVPWi1MbNYivU_Pw-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 09/20] s390x/tcg: check for addressing exceptions for RRBE, SSKE and ISKE Date: Tue, 7 Sep 2021 15:14:38 +0200 Message-Id: <20210907131449.493875-10-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631021847985100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Let's replace the ram_size check by a proper physical address space check (for example, to prepare for memory hotplug), trigger addressing exceptions and trace the return value of the storage key getter/setter. Provide an helper mmu_absolute_addr_valid() to be used in other context soon. Always test for "read" instead of "write" as we are not actually modifying the page itself. Signed-off-by: David Hildenbrand Acked-by: Thomas Huth Message-Id: <20210903155514.44772-5-david@redhat.com> Signed-off-by: Thomas Huth --- target/s390x/helper.h | 6 +++--- target/s390x/mmu_helper.c | 8 ++++++++ target/s390x/s390x-internal.h | 1 + target/s390x/tcg/mem_helper.c | 36 ++++++++++++++++++++++------------- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/target/s390x/helper.h b/target/s390x/helper.h index 6215ca00bc..271b081e8c 100644 --- a/target/s390x/helper.h +++ b/target/s390x/helper.h @@ -336,9 +336,9 @@ DEF_HELPER_FLAGS_4(stctl, TCG_CALL_NO_WG, void, env, i3= 2, i64, i32) DEF_HELPER_FLAGS_4(stctg, TCG_CALL_NO_WG, void, env, i32, i64, i32) DEF_HELPER_FLAGS_2(testblock, TCG_CALL_NO_WG, i32, env, i64) DEF_HELPER_FLAGS_3(tprot, TCG_CALL_NO_WG, i32, env, i64, i64) -DEF_HELPER_FLAGS_2(iske, TCG_CALL_NO_RWG_SE, i64, env, i64) -DEF_HELPER_FLAGS_3(sske, TCG_CALL_NO_RWG, void, env, i64, i64) -DEF_HELPER_FLAGS_2(rrbe, TCG_CALL_NO_RWG, i32, env, i64) +DEF_HELPER_2(iske, i64, env, i64) +DEF_HELPER_3(sske, void, env, i64, i64) +DEF_HELPER_2(rrbe, i32, env, i64) DEF_HELPER_4(mvcs, i32, env, i64, i64, i64) DEF_HELPER_4(mvcp, i32, env, i64, i64, i64) DEF_HELPER_4(sigp, i32, env, i64, i32, i32) diff --git a/target/s390x/mmu_helper.c b/target/s390x/mmu_helper.c index d779a9fc51..0620b1803e 100644 --- a/target/s390x/mmu_helper.c +++ b/target/s390x/mmu_helper.c @@ -94,6 +94,14 @@ target_ulong mmu_real2abs(CPUS390XState *env, target_ulo= ng raddr) return raddr; } =20 +bool mmu_absolute_addr_valid(target_ulong addr, bool is_write) +{ + return address_space_access_valid(&address_space_memory, + addr & TARGET_PAGE_MASK, + TARGET_PAGE_SIZE, is_write, + MEMTXATTRS_UNSPECIFIED); +} + static inline bool read_table_entry(CPUS390XState *env, hwaddr gaddr, uint64_t *entry) { diff --git a/target/s390x/s390x-internal.h b/target/s390x/s390x-internal.h index 5506f185e8..d246d26b04 100644 --- a/target/s390x/s390x-internal.h +++ b/target/s390x/s390x-internal.h @@ -373,6 +373,7 @@ void probe_write_access(CPUS390XState *env, uint64_t ad= dr, uint64_t len, =20 =20 /* mmu_helper.c */ +bool mmu_absolute_addr_valid(target_ulong addr, bool is_write); int mmu_translate(CPUS390XState *env, target_ulong vaddr, int rw, uint64_t= asc, target_ulong *raddr, int *flags, uint64_t *tec); int mmu_translate_real(CPUS390XState *env, target_ulong raddr, int rw, diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c index dd506d8d17..a44a107374 100644 --- a/target/s390x/tcg/mem_helper.c +++ b/target/s390x/tcg/mem_helper.c @@ -28,6 +28,7 @@ #include "qemu/int128.h" #include "qemu/atomic128.h" #include "tcg/tcg.h" +#include "trace.h" =20 #if !defined(CONFIG_USER_ONLY) #include "hw/s390x/storage-keys.h" @@ -2171,15 +2172,15 @@ uint32_t HELPER(tprot)(CPUS390XState *env, uint64_t= a1, uint64_t a2) /* insert storage key extended */ uint64_t HELPER(iske)(CPUS390XState *env, uint64_t r2) { - MachineState *ms =3D MACHINE(qdev_get_machine()); static S390SKeysState *ss; static S390SKeysClass *skeyclass; uint64_t addr =3D wrap_address(env, r2); uint8_t key; + int rc; =20 addr =3D mmu_real2abs(env, addr); - if (addr > ms->ram_size) { - return 0; + if (!mmu_absolute_addr_valid(addr, false)) { + tcg_s390_program_interrupt(env, PGM_ADDRESSING, GETPC()); } =20 if (unlikely(!ss)) { @@ -2187,7 +2188,9 @@ uint64_t HELPER(iske)(CPUS390XState *env, uint64_t r2) skeyclass =3D S390_SKEYS_GET_CLASS(ss); } =20 - if (skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key)) { + rc =3D skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); + if (rc) { + trace_get_skeys_nonzero(rc); return 0; } return key; @@ -2196,15 +2199,15 @@ uint64_t HELPER(iske)(CPUS390XState *env, uint64_t = r2) /* set storage key extended */ void HELPER(sske)(CPUS390XState *env, uint64_t r1, uint64_t r2) { - MachineState *ms =3D MACHINE(qdev_get_machine()); static S390SKeysState *ss; static S390SKeysClass *skeyclass; uint64_t addr =3D wrap_address(env, r2); uint8_t key; + int rc; =20 addr =3D mmu_real2abs(env, addr); - if (addr > ms->ram_size) { - return; + if (!mmu_absolute_addr_valid(addr, false)) { + tcg_s390_program_interrupt(env, PGM_ADDRESSING, GETPC()); } =20 if (unlikely(!ss)) { @@ -2213,7 +2216,10 @@ void HELPER(sske)(CPUS390XState *env, uint64_t r1, u= int64_t r2) } =20 key =3D r1 & 0xfe; - skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); + rc =3D skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); + if (rc) { + trace_set_skeys_nonzero(rc); + } /* * As we can only flush by virtual address and not all the entries * that point to a physical address we have to flush the whole TLB. @@ -2224,15 +2230,15 @@ void HELPER(sske)(CPUS390XState *env, uint64_t r1, = uint64_t r2) /* reset reference bit extended */ uint32_t HELPER(rrbe)(CPUS390XState *env, uint64_t r2) { - MachineState *ms =3D MACHINE(qdev_get_machine()); uint64_t addr =3D wrap_address(env, r2); static S390SKeysState *ss; static S390SKeysClass *skeyclass; uint8_t re, key; + int rc; =20 addr =3D mmu_real2abs(env, addr); - if (addr > ms->ram_size) { - return 0; + if (!mmu_absolute_addr_valid(addr, false)) { + tcg_s390_program_interrupt(env, PGM_ADDRESSING, GETPC()); } =20 if (unlikely(!ss)) { @@ -2240,14 +2246,18 @@ uint32_t HELPER(rrbe)(CPUS390XState *env, uint64_t = r2) skeyclass =3D S390_SKEYS_GET_CLASS(ss); } =20 - if (skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key)) { + rc =3D skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); + if (rc) { + trace_get_skeys_nonzero(rc); return 0; } =20 re =3D key & (SK_R | SK_C); key &=3D ~SK_R; =20 - if (skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key)) { + rc =3D skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); + if (rc) { + trace_set_skeys_nonzero(rc); return 0; } /* --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631022264; cv=none; d=zohomail.com; s=zohoarc; b=eGtbMfLCUUgjH+CCGQOTnH5qICdv6w9FNvA1/xJCbmBL0W2KPJCAASmdEdug54qO78aqezlFPlhAm1kxlgjBljFeYYyNjT+T5tFv212d+cVMjmOlyT5sCzvTrRJdedV7pEZDje0Bbi5Cq5sViLI12IE3xQXOnMy3P5frMf+0wJk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631022264; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lk9V/pl3oBsyaaQZTposHSvXC8OsYh0jzadd9wquGXk=; b=WjrWs8eW9r6dk5v4Jnakj4b0ceP1ROiNx5F2NvhjpyF/T1QqzWZf+ksHZsv8mh1JsP2ReH1Y+OzFIVBxHGPn462GhPErjx5BD62iMX9vGkf/RYQ1+E3odhJDt3kMWTeBDitMmFaUZAUDv2lKFAq/ZPdi7WJbTB8tGdyKcy+92kg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631022264689818.9105823005966; Tue, 7 Sep 2021 06:44:24 -0700 (PDT) Received: from localhost ([::1]:55440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbOh-0008MY-Nj for importer@patchew.org; Tue, 07 Sep 2021 09:44:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawq-0003Ih-FQ for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38816) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawn-0002Xb-Q6 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:36 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-434-NnLATSxGMSaK9j6AFllDyA-1; Tue, 07 Sep 2021 09:15:31 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DF29A107ACCD; Tue, 7 Sep 2021 13:15:30 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCFE75C1B4; Tue, 7 Sep 2021 13:15:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020533; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lk9V/pl3oBsyaaQZTposHSvXC8OsYh0jzadd9wquGXk=; b=YK8PCy15dJWCHwqPNnu9e97G6pl3tbzmwRDu+Dd12X8IHlFboYhNFrCidhksYZdWxyJ77M qtodkSM5DrbSeoaFxlarqHI7snocG8PA4p6wCqv0EQM3SMA31Gp5Muy0gmSkzhPcUBuKSb 2Jryzf73oRAqaMBrhox4cUOKiFjlu7c= X-MC-Unique: NnLATSxGMSaK9j6AFllDyA-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 10/20] s390x/mmu_helper: no need to pass access type to mmu_translate_asce() Date: Tue, 7 Sep 2021 15:14:39 +0200 Message-Id: <20210907131449.493875-11-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631022265411100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand The access type is unused since commit 81d7e3bc45 ("s390x/mmu: Inject DAT exceptions from a single place"). Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth Message-Id: <20210903155514.44772-6-david@redhat.com> Signed-off-by: Thomas Huth --- target/s390x/mmu_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/s390x/mmu_helper.c b/target/s390x/mmu_helper.c index 0620b1803e..167f1b1455 100644 --- a/target/s390x/mmu_helper.c +++ b/target/s390x/mmu_helper.c @@ -125,7 +125,7 @@ static inline bool read_table_entry(CPUS390XState *env,= hwaddr gaddr, =20 static int mmu_translate_asce(CPUS390XState *env, target_ulong vaddr, uint64_t asc, uint64_t asce, target_ulong *r= addr, - int *flags, int rw) + int *flags) { const bool edat1 =3D (env->cregs[0] & CR0_EDAT) && s390_has_feat(S390_FEAT_EDAT); @@ -428,7 +428,7 @@ int mmu_translate(CPUS390XState *env, target_ulong vadd= r, int rw, uint64_t asc, } =20 /* perform the DAT translation */ - r =3D mmu_translate_asce(env, vaddr, asc, asce, raddr, flags, rw); + r =3D mmu_translate_asce(env, vaddr, asc, asce, raddr, flags); if (unlikely(r)) { return r; } --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631022460; cv=none; d=zohomail.com; s=zohoarc; b=MV1zj4QNRmW7RiDp6gyUtSgMAuaiAzrXAw+hJDR46lN9/ujjqwiKl7rjNGf8vkLH0FxviSKmaKUfDbs/aOdBKYj87HUkplTGeGANFpz7dkDjiguG1SlQ7KFkkasLdXWjNHyGyayAxwYD2uOtArx1z4cbRdkaRi0FEjIv/ZmD64Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631022460; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=b6ZVTQs70Xpb7FE0bSCZCezQeMVdMSEdhwlbYGBkpt0=; b=DnYn8k0Jo5ZpMEBIqVklU4tArJt7zLMxu+RlIWBleOh3tJIF5/Cj/22EwuKsajwTQ6DqWzroPwBl8+bXeGDDNEWFX/3NozZLTBweVegBfGIsJNK7ORKf/pMvprNeniqVS4qn3XSQd3yQIflLav7PiYCBSc9FLQ0cm2jmElRF/3Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631022460645345.36776195185337; Tue, 7 Sep 2021 06:47:40 -0700 (PDT) Received: from localhost ([::1]:33772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbRr-0004Zn-BT for importer@patchew.org; Tue, 07 Sep 2021 09:47:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawt-0003Ln-U6 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37587) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawq-0002Yy-26 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:39 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-384-HuJYy8-MPKyBGau-mg33Og-1; Tue, 07 Sep 2021 09:15:33 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D0DA802937; Tue, 7 Sep 2021 13:15:32 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AB835C1B4; Tue, 7 Sep 2021 13:15:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b6ZVTQs70Xpb7FE0bSCZCezQeMVdMSEdhwlbYGBkpt0=; b=WRAk+55QxK1fS/smVk9h2TvZ2qWJlqnNOHvKZSrXzN9sZfgMzr+NF0HeXsVa5xtrMo4Q+d +mkxplSNW0z0fRxBGU3s8Q0f7bXHR6FqBsjBa1P0YOaokHfEmT2AJwC8e2Bg+N7jQkRmuF i0eD8fhdmzxtdwI7ExcJeDDWqABKJeo= X-MC-Unique: HuJYy8-MPKyBGau-mg33Og-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 11/20] s390x/mmu_helper: fixup mmu_translate() documentation Date: Tue, 7 Sep 2021 15:14:40 +0200 Message-Id: <20210907131449.493875-12-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631022461420100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Looks like we forgot to adjust documentation of one parameter. Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth Message-Id: <20210903155514.44772-7-david@redhat.com> Signed-off-by: Thomas Huth --- target/s390x/mmu_helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/s390x/mmu_helper.c b/target/s390x/mmu_helper.c index 167f1b1455..ca25dadb5b 100644 --- a/target/s390x/mmu_helper.c +++ b/target/s390x/mmu_helper.c @@ -374,7 +374,8 @@ static void mmu_handle_skey(target_ulong addr, int rw, = int *flags) * @param asc address space control (one of the PSW_ASC_* modes) * @param raddr the translated address is stored to this pointer * @param flags the PAGE_READ/WRITE/EXEC flags are stored to this pointer - * @param exc true =3D inject a program check if a fault occurred + * @param tec the translation exception code if stored to this pointer = if + * there is an exception to raise * @return 0 =3D success, !=3D 0, the exception to raise */ int mmu_translate(CPUS390XState *env, target_ulong vaddr, int rw, uint64_t= asc, --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631021999; cv=none; d=zohomail.com; s=zohoarc; b=B1eEQfceNK7YO9YEckaeSknNflQo6vcZ8IpB5GmGfCOeO1jEiuT766mxYtIiKxWeiA1+g2K++HjYUnUK/LcoQ+Svkb2GiiU32KzZQrE+EeihjMxbfXAToxt1+1O5AEdpQFMxgTVYGYipIvBksVkNrdM/KCSUyFriOzTaTyIBMTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631021999; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=E+i2SUVw5T/UjbuJURGFHkx/Lk7LedjKvi+jlxOA1RQ=; b=kMg2gOhRkgr7ETZAvaIOLzIbTKMZCYiSX7sm5VuVen/Vy+yEBdiFgzCA0LcGUoJdNuYlIeI6GhNeAfNqhePRqm9o8kw3+09OU4xYar2nu3ME6LF03hJQH9EA83H3YEKApKL6N7x6yJc7S0fkws/7q+regH9akMKNRh9lLEDJ8Zk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631021999638782.2469622457163; Tue, 7 Sep 2021 06:39:59 -0700 (PDT) Received: from localhost ([::1]:38420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbKQ-0004xE-I5 for importer@patchew.org; Tue, 07 Sep 2021 09:39:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawx-0003Nz-4r for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40266) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawt-0002c7-Tj for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:42 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-146-cxHDIRYFOVGBufJlS2uBPg-1; Tue, 07 Sep 2021 09:15:37 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E418A8145E7; Tue, 7 Sep 2021 13:15:36 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD28E5C1B4; Tue, 7 Sep 2021 13:15:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E+i2SUVw5T/UjbuJURGFHkx/Lk7LedjKvi+jlxOA1RQ=; b=I3kvdzC8li7os4qDlfb7nfID+UIakV1uFDmBCw840q6Vl6AHR+HTSVBmrj3yPunZPI+dyX uMJH5TDx9rtyAhunG5bBJnLIq0dBBjTMiVkGXyHfb6OvVOJ9hp2Ek4x7Sz7QI0c5RbSVgH 02zgjHVV2NYtfbEzbMkKys6Vi5G2cro= X-MC-Unique: cxHDIRYFOVGBufJlS2uBPg-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 12/20] s390x/mmu_helper: move address validation into mmu_translate*() Date: Tue, 7 Sep 2021 15:14:41 +0200 Message-Id: <20210907131449.493875-13-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631022001431100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Let's move address validation into mmu_translate() and mmu_translate_real(). This allows for checking whether an absolute address is valid before looking up the storage key. We can now get rid of the ram_size check. Interestingly, we're already handling LOAD REAL ADDRESS wrong, because a) We're not supposed to touch storage keys b) We're not supposed to convert to an absolute address Let's use a fake, negative MMUAccessType to teach mmu_translate() to fix that handling and to not perform address validation. Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth Message-Id: <20210903155514.44772-8-david@redhat.com> Signed-off-by: Thomas Huth --- target/s390x/mmu_helper.c | 36 ++++++++++++++++++++-------------- target/s390x/s390x-internal.h | 2 ++ target/s390x/tcg/excp_helper.c | 13 ------------ target/s390x/tcg/mem_helper.c | 2 +- 4 files changed, 24 insertions(+), 29 deletions(-) diff --git a/target/s390x/mmu_helper.c b/target/s390x/mmu_helper.c index ca25dadb5b..de6df928d2 100644 --- a/target/s390x/mmu_helper.c +++ b/target/s390x/mmu_helper.c @@ -301,14 +301,13 @@ static void mmu_handle_skey(target_ulong addr, int rw= , int *flags) { static S390SKeysClass *skeyclass; static S390SKeysState *ss; - MachineState *ms =3D MACHINE(qdev_get_machine()); uint8_t key; int rc; =20 - if (unlikely(addr >=3D ms->ram_size)) { - return; - } - + /* + * We expect to be called with an absolute address that has already be= en + * validated, such that we can reliably use it to lookup the storage k= ey. + */ if (unlikely(!ss)) { ss =3D s390_get_skeys_device(); skeyclass =3D S390_SKEYS_GET_CLASS(ss); @@ -370,7 +369,7 @@ static void mmu_handle_skey(target_ulong addr, int rw, = int *flags) /** * Translate a virtual (logical) address into a physical (absolute) addres= s. * @param vaddr the virtual address - * @param rw 0 =3D read, 1 =3D write, 2 =3D code fetch + * @param rw 0 =3D read, 1 =3D write, 2 =3D code fetch, < 0 =3D load r= eal address * @param asc address space control (one of the PSW_ASC_* modes) * @param raddr the translated address is stored to this pointer * @param flags the PAGE_READ/WRITE/EXEC flags are stored to this pointer @@ -449,10 +448,17 @@ int mmu_translate(CPUS390XState *env, target_ulong va= ddr, int rw, uint64_t asc, } =20 nodat: - /* Convert real address -> absolute address */ - *raddr =3D mmu_real2abs(env, *raddr); + if (rw >=3D 0) { + /* Convert real address -> absolute address */ + *raddr =3D mmu_real2abs(env, *raddr); =20 - mmu_handle_skey(*raddr, rw, flags); + if (!mmu_absolute_addr_valid(*raddr, rw =3D=3D MMU_DATA_STORE)) { + *tec =3D 0; /* unused */ + return PGM_ADDRESSING; + } + + mmu_handle_skey(*raddr, rw, flags); + } return 0; } =20 @@ -473,12 +479,6 @@ static int translate_pages(S390CPU *cpu, vaddr addr, i= nt nr_pages, if (ret) { return ret; } - if (!address_space_access_valid(&address_space_memory, pages[i], - TARGET_PAGE_SIZE, is_write, - MEMTXATTRS_UNSPECIFIED)) { - *tec =3D 0; /* unused */ - return PGM_ADDRESSING; - } addr +=3D TARGET_PAGE_SIZE; } =20 @@ -588,6 +588,12 @@ int mmu_translate_real(CPUS390XState *env, target_ulon= g raddr, int rw, =20 *addr =3D mmu_real2abs(env, raddr & TARGET_PAGE_MASK); =20 + if (!mmu_absolute_addr_valid(*addr, rw =3D=3D MMU_DATA_STORE)) { + /* unused */ + *tec =3D 0; + return PGM_ADDRESSING; + } + mmu_handle_skey(*addr, rw, flags); return 0; } diff --git a/target/s390x/s390x-internal.h b/target/s390x/s390x-internal.h index d246d26b04..7a6aa4dacc 100644 --- a/target/s390x/s390x-internal.h +++ b/target/s390x/s390x-internal.h @@ -374,6 +374,8 @@ void probe_write_access(CPUS390XState *env, uint64_t ad= dr, uint64_t len, =20 /* mmu_helper.c */ bool mmu_absolute_addr_valid(target_ulong addr, bool is_write); +/* Special access mode only valid for mmu_translate() */ +#define MMU_S390_LRA -1 int mmu_translate(CPUS390XState *env, target_ulong vaddr, int rw, uint64_t= asc, target_ulong *raddr, int *flags, uint64_t *tec); int mmu_translate_real(CPUS390XState *env, target_ulong raddr, int rw, diff --git a/target/s390x/tcg/excp_helper.c b/target/s390x/tcg/excp_helper.c index a61917d04f..3d6662a53c 100644 --- a/target/s390x/tcg/excp_helper.c +++ b/target/s390x/tcg/excp_helper.c @@ -150,19 +150,6 @@ bool s390_cpu_tlb_fill(CPUState *cs, vaddr address, in= t size, g_assert_not_reached(); } =20 - /* check out of RAM access */ - if (!excp && - !address_space_access_valid(&address_space_memory, raddr, - TARGET_PAGE_SIZE, access_type, - MEMTXATTRS_UNSPECIFIED)) { - MachineState *ms =3D MACHINE(qdev_get_machine()); - qemu_log_mask(CPU_LOG_MMU, - "%s: raddr %" PRIx64 " > ram_size %" PRIx64 "\n", - __func__, (uint64_t)raddr, (uint64_t)ms->ram_size); - excp =3D PGM_ADDRESSING; - tec =3D 0; /* unused */ - } - env->tlb_fill_exc =3D excp; env->tlb_fill_tec =3D tec; =20 diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c index a44a107374..4f9f3e1f63 100644 --- a/target/s390x/tcg/mem_helper.c +++ b/target/s390x/tcg/mem_helper.c @@ -2455,7 +2455,7 @@ uint64_t HELPER(lra)(CPUS390XState *env, uint64_t add= r) tcg_s390_program_interrupt(env, PGM_SPECIAL_OP, GETPC()); } =20 - exc =3D mmu_translate(env, addr, 0, asc, &ret, &flags, &tec); + exc =3D mmu_translate(env, addr, MMU_S390_LRA, asc, &ret, &flags, &tec= ); if (exc) { cc =3D 3; ret =3D exc | 0x80000000; --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631022659; cv=none; d=zohomail.com; s=zohoarc; b=MG4IxcTB4DS6vdYu5+aCeRiUOAmnzch1s7oxrAQ9RBwmZgyADVOR98WAYUwF2l2qfDYocGslqumBPXpBoMD3BQNZFlXoktB8i61PaS5FlctojpdgCK3FY4SNf8gMpk5uNsjwCjjmtVEEu5OB5OJzlynIRlg/kUggNl/EN3NjqnU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631022659; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ig/yAAGXleUETsSBfnb26Ws7WCjlfLXvRmQkq2OaEwU=; b=UkhW7SwWsnzzP4SYZvclFFpi0aJtD6LuZNT05WZ01x2j83clSKOLQto5wcYH3Dzkefl21EAj4hXi9tG1vOwqDSXwV4fdXmPgI8vvtIU9WkaO3wGZlJgBOsgqBDomXk+tmTQjaO0Y7bZpJ9zIAgRuG2BKVAhE8bPEfLZLXTITCeQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631022659843386.10661565995497; Tue, 7 Sep 2021 06:50:59 -0700 (PDT) Received: from localhost ([::1]:40884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbV4-0000ys-Jb for importer@patchew.org; Tue, 07 Sep 2021 09:50:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNax0-0003R8-LH for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:22883) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawv-0002dB-Mv for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:46 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-1-4uIyofr3NXWmAkhKun71Fg-1; Tue, 07 Sep 2021 09:15:39 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9637A800FF3; Tue, 7 Sep 2021 13:15:38 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 543C15C1B4; Tue, 7 Sep 2021 13:15:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020541; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ig/yAAGXleUETsSBfnb26Ws7WCjlfLXvRmQkq2OaEwU=; b=WCBwsBmbOIrjmwh3wGddGr0DTNiUl7YYHIeSlZTV+RZPgR28vJ+0wyzaG1+0wy0vKHkrcw uV9IgU+84WdiuuTniAdoXZKBy/t/14KJATGnGIHuXLF8uipLpzT6XiGz5847dGDwOk8KcA Mjr7MIRuG32c9zaBSmvdDz83FYPkNmw= X-MC-Unique: 4uIyofr3NXWmAkhKun71Fg-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 13/20] s390x/mmu_helper: avoid setting the storage key if nothing changed Date: Tue, 7 Sep 2021 15:14:42 +0200 Message-Id: <20210907131449.493875-14-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631022660931100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Avoid setting the key if nothing changed. Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth Message-Id: <20210903155514.44772-9-david@redhat.com> Signed-off-by: Thomas Huth --- target/s390x/mmu_helper.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/target/s390x/mmu_helper.c b/target/s390x/mmu_helper.c index de6df928d2..e2b372efd9 100644 --- a/target/s390x/mmu_helper.c +++ b/target/s390x/mmu_helper.c @@ -301,7 +301,7 @@ static void mmu_handle_skey(target_ulong addr, int rw, = int *flags) { static S390SKeysClass *skeyclass; static S390SKeysState *ss; - uint8_t key; + uint8_t key, old_key; int rc; =20 /* @@ -337,6 +337,7 @@ static void mmu_handle_skey(target_ulong addr, int rw, = int *flags) trace_get_skeys_nonzero(rc); return; } + old_key =3D key; =20 switch (rw) { case MMU_DATA_LOAD: @@ -360,9 +361,11 @@ static void mmu_handle_skey(target_ulong addr, int rw,= int *flags) /* Any store/fetch sets the reference bit */ key |=3D SK_R; =20 - rc =3D skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); - if (rc) { - trace_set_skeys_nonzero(rc); + if (key !=3D old_key) { + rc =3D skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); + if (rc) { + trace_set_skeys_nonzero(rc); + } } } =20 --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631022777; cv=none; d=zohomail.com; s=zohoarc; b=diFz/o7UFlCd/G8Bs6tht+vId5st/m10F4mgbJ3PdKuzMKgzLDMn+nFe7Exdy25uZjzvWMOY2pdH/dcUlFbqV0GTjxHUmEHSVhrHgc5sDtfBiC2r0W1WkLqBA+RgdH2npeyADhDi5Hrn+qW9SL+G/OOKAUh7YKfeerbksxn6nM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631022777; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EyRKBEE5XvzPdybRDy+QtAPXVQ49RURS/fPc5lpyM3k=; b=nFwZxT2E2PFNS8Q04aXve1a8ZeQIVevA/TwTpa1/lu3OxKL9mA/onR5qhOMJ61VbdTdNJJ7gFFe3dsHtziMn3+yM+FoTDWtErmEvNlKwKB1sDcewxgtlVg06qCWAkrXOwXDawlfMvJxWJ9o0DHEgaWhebVtmeSH9YMYmNRB0A7c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631022777075841.9882050042957; Tue, 7 Sep 2021 06:52:57 -0700 (PDT) Received: from localhost ([::1]:47138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbWx-0005GQ-Tf for importer@patchew.org; Tue, 07 Sep 2021 09:52:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNax2-0003X4-Bi for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29026) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNawx-0002e4-0B for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:48 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-586-kv-NZGSZPsCAk9kKda_K0Q-1; Tue, 07 Sep 2021 09:15:41 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47C0F107ACC7; Tue, 7 Sep 2021 13:15:40 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16CFB5C1B4; Tue, 7 Sep 2021 13:15:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EyRKBEE5XvzPdybRDy+QtAPXVQ49RURS/fPc5lpyM3k=; b=ADJowgQAjzNALeDuEveMBDFPG+l5IWcaQOv+80znPvA5uESfp2jeqzj/pI5hGEHjcLwDka p0SRdAGD7IDuC6hetJbc4G1jkETlBlbC3z+FziUc1qyjhsWV64rGh/eBT/YXk37cVMcIjs LJeR/SHCLtZHAFiMPjJvliAm0Opo1FQ= X-MC-Unique: kv-NZGSZPsCAk9kKda_K0Q-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 14/20] hw/s390x/s390-skeys: use memory mapping to detect which storage keys to migrate Date: Tue, 7 Sep 2021 15:14:43 +0200 Message-Id: <20210907131449.493875-15-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631022778900100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Let's use the guest_phys_blocks API to get physical memory regions that are well defined inside our physical address space and migrate the storage keys of these. This is a preparation for having memory besides initial ram defined in the guest physical address space, for example, via memory devices. We get rid of the ms->ram_size dependency. Please note that we will usually have very little (--> 1) physical ranges. With virtio-mem might have significantly more ranges in the future. If that turns out to be a problem (e.g., total memory footprint of the list), we could look into a memory mapping API that avoids creation of a list and instead triggers a callback for each range. Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth Message-Id: <20210903155514.44772-10-david@redhat.com> Signed-off-by: Thomas Huth --- hw/s390x/s390-skeys.c | 70 ++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index 9a8d60d1d9..250685a95a 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -17,6 +17,7 @@ #include "qapi/qapi-commands-misc-target.h" #include "qapi/qmp/qdict.h" #include "qemu/error-report.h" +#include "sysemu/memory_mapping.h" #include "sysemu/kvm.h" #include "migration/qemu-file-types.h" #include "migration/register.h" @@ -257,10 +258,9 @@ static void s390_storage_keys_save(QEMUFile *f, void *= opaque) { S390SKeysState *ss =3D S390_SKEYS(opaque); S390SKeysClass *skeyclass =3D S390_SKEYS_GET_CLASS(ss); - MachineState *ms =3D MACHINE(qdev_get_machine()); - uint64_t pages_left =3D ms->ram_size / TARGET_PAGE_SIZE; - uint64_t read_count, eos =3D S390_SKEYS_SAVE_FLAG_EOS; - vaddr cur_gfn =3D 0; + GuestPhysBlockList guest_phys_blocks; + GuestPhysBlock *block; + uint64_t pages, gfn; int error =3D 0; uint8_t *buf; =20 @@ -274,36 +274,52 @@ static void s390_storage_keys_save(QEMUFile *f, void = *opaque) goto end_stream; } =20 - /* We only support initial memory. Standby memory is not handled yet. = */ - qemu_put_be64(f, (cur_gfn * TARGET_PAGE_SIZE) | S390_SKEYS_SAVE_FLAG_S= KEYS); - qemu_put_be64(f, pages_left); - - while (pages_left) { - read_count =3D MIN(pages_left, S390_SKEYS_BUFFER_SIZE); - - if (!error) { - error =3D skeyclass->get_skeys(ss, cur_gfn, read_count, buf); - if (error) { - /* - * If error: we want to fill the stream with valid data in= stead - * of stopping early so we pad the stream with 0x00 values= and - * use S390_SKEYS_SAVE_FLAG_ERROR to indicate failure to t= he - * reading side. - */ - error_report("S390_GET_KEYS error %d", error); - memset(buf, 0, S390_SKEYS_BUFFER_SIZE); - eos =3D S390_SKEYS_SAVE_FLAG_ERROR; + guest_phys_blocks_init(&guest_phys_blocks); + guest_phys_blocks_append(&guest_phys_blocks); + + /* Send each contiguous physical memory range separately. */ + QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) { + assert(QEMU_IS_ALIGNED(block->target_start, TARGET_PAGE_SIZE)); + assert(QEMU_IS_ALIGNED(block->target_end, TARGET_PAGE_SIZE)); + + gfn =3D block->target_start / TARGET_PAGE_SIZE; + pages =3D (block->target_end - block->target_start) / TARGET_PAGE_= SIZE; + qemu_put_be64(f, block->target_start | S390_SKEYS_SAVE_FLAG_SKEYS); + qemu_put_be64(f, pages); + + while (pages) { + const uint64_t cur_pages =3D MIN(pages, S390_SKEYS_BUFFER_SIZE= ); + + if (!error) { + error =3D skeyclass->get_skeys(ss, gfn, cur_pages, buf); + if (error) { + /* + * Create a valid stream with all 0x00 and indicate + * S390_SKEYS_SAVE_FLAG_ERROR to the destination. + */ + error_report("S390_GET_KEYS error %d", error); + memset(buf, 0, S390_SKEYS_BUFFER_SIZE); + } } + + qemu_put_buffer(f, buf, cur_pages); + gfn +=3D cur_pages; + pages -=3D cur_pages; } =20 - qemu_put_buffer(f, buf, read_count); - cur_gfn +=3D read_count; - pages_left -=3D read_count; + if (error) { + break; + } } =20 + guest_phys_blocks_free(&guest_phys_blocks); g_free(buf); end_stream: - qemu_put_be64(f, eos); + if (error) { + qemu_put_be64(f, S390_SKEYS_SAVE_FLAG_ERROR); + } else { + qemu_put_be64(f, S390_SKEYS_SAVE_FLAG_EOS); + } } =20 static int s390_storage_keys_load(QEMUFile *f, void *opaque, int version_i= d) --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631021288; cv=none; d=zohomail.com; s=zohoarc; b=Nfh63ajcQ8ecZH2y+R2ow4bZPLGbYVKHETlV8JghPC2XUacsU0fhWJA+12Xpx8o+ODew7Kf9EKojQCDpSBC2O0tI9VFC3tI92ushB16AAayv72mqeLHav37LpgFcPYhXbKc5BnjLFejE5RZaOSP3moaDAw1zSUTIcSBZHc7E7zc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631021288; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Q+Ux7jaz3DAtJFc+QuiruOhg4UNlpAdvMbvtvSYWNyc=; b=bN3Px3HK9YRsg9tS4X2GBfzsJEBiKxNcffQ+UNlhlsdS2kaS3Kp9JispcD5vrOAejQTyEA3pbzBp8GxeKb5Az9vVlAV4cGxuMYhkyH5pWIa2i9swBSTEjD6UbMCsng+NdGxpoVXsrNoa+VDoWMdlBNhxyuVuj5qQMr7MHR7lrSY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16310212887140.15101135400493604; Tue, 7 Sep 2021 06:28:08 -0700 (PDT) Received: from localhost ([::1]:58642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNb8x-0005F3-L0 for importer@patchew.org; Tue, 07 Sep 2021 09:28:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNax9-0003qc-CP for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59795) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNax6-0002i4-Gu for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:55 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-366-uqbDufUiMISwnQrJhQ57QA-1; Tue, 07 Sep 2021 09:15:44 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E84D4800FF3; Tue, 7 Sep 2021 13:15:41 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id B08005C1B4; Tue, 7 Sep 2021 13:15:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020551; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q+Ux7jaz3DAtJFc+QuiruOhg4UNlpAdvMbvtvSYWNyc=; b=Y67FWhwVg02ZnSPNaib6WyBnFDilJ4ndUmd4FK62nj+Ej36+tKCRMpqunilaBOzblKC+Fi gD6t0FhQ5T9huFIFvkjfT1sA9oIEDliGanX+FLzGq5yUFgYs44MZ3fUfosDjvcKRyowY+B XCrEeMk4cVbz9IVMDM0t0CWo/raRxfI= X-MC-Unique: uqbDufUiMISwnQrJhQ57QA-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 15/20] hw/s390x/s390-skeys: use memory mapping to detect which storage keys to dump Date: Tue, 7 Sep 2021 15:14:44 +0200 Message-Id: <20210907131449.493875-16-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631021289898100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Handle it similar to migration. Assert that we're holding the BQL, to make sure we don't see concurrent modifications. Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth Message-Id: <20210903155514.44772-11-david@redhat.com> Signed-off-by: Thomas Huth --- hw/s390x/s390-skeys.c | 50 ++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index 250685a95a..56a47fe180 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -110,11 +110,10 @@ void qmp_dump_skeys(const char *filename, Error **err= p) { S390SKeysState *ss =3D s390_get_skeys_device(); S390SKeysClass *skeyclass =3D S390_SKEYS_GET_CLASS(ss); - MachineState *ms =3D MACHINE(qdev_get_machine()); - const uint64_t total_count =3D ms->ram_size / TARGET_PAGE_SIZE; - uint64_t handled_count =3D 0, cur_count; + GuestPhysBlockList guest_phys_blocks; + GuestPhysBlock *block; + uint64_t pages, gfn; Error *lerr =3D NULL; - vaddr cur_gfn =3D 0; uint8_t *buf; int ret; int fd; @@ -145,28 +144,39 @@ void qmp_dump_skeys(const char *filename, Error **err= p) goto out; } =20 - /* we'll only dump initial memory for now */ - while (handled_count < total_count) { - /* Calculate how many keys to ask for & handle overflow case */ - cur_count =3D MIN(total_count - handled_count, S390_SKEYS_BUFFER_S= IZE); + assert(qemu_mutex_iothread_locked()); + guest_phys_blocks_init(&guest_phys_blocks); + guest_phys_blocks_append(&guest_phys_blocks); =20 - ret =3D skeyclass->get_skeys(ss, cur_gfn, cur_count, buf); - if (ret < 0) { - error_setg(errp, "get_keys error %d", ret); - goto out_free; - } + QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) { + assert(QEMU_IS_ALIGNED(block->target_start, TARGET_PAGE_SIZE)); + assert(QEMU_IS_ALIGNED(block->target_end, TARGET_PAGE_SIZE)); =20 - /* write keys to stream */ - write_keys(f, buf, cur_gfn, cur_count, &lerr); - if (lerr) { - goto out_free; - } + gfn =3D block->target_start / TARGET_PAGE_SIZE; + pages =3D (block->target_end - block->target_start) / TARGET_PAGE_= SIZE; =20 - cur_gfn +=3D cur_count; - handled_count +=3D cur_count; + while (pages) { + const uint64_t cur_pages =3D MIN(pages, S390_SKEYS_BUFFER_SIZE= ); + + ret =3D skeyclass->get_skeys(ss, gfn, cur_pages, buf); + if (ret < 0) { + error_setg_errno(errp, -ret, "get_keys error"); + goto out_free; + } + + /* write keys to stream */ + write_keys(f, buf, gfn, cur_pages, &lerr); + if (lerr) { + goto out_free; + } + + gfn +=3D cur_pages; + pages -=3D cur_pages; + } } =20 out_free: + guest_phys_blocks_free(&guest_phys_blocks); error_propagate(errp, lerr); g_free(buf); out: --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631022120; cv=none; d=zohomail.com; s=zohoarc; b=c7Yckou5Z+loc/EUwydsgv73xpJRz3KNT8U+rGCSovbzsR7rwmfqOlGO8Wxbcmj07CAPYRF0xbemvTj9MVuQvs2lNvedfzpwJPtxEzGbo8sthgMZWS0DZ2lUUWLIk20nLjqYXZiN24ktYzY0zgY+617gimFRFoq9LYK+ZsIY1dc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631022120; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=32PbFx+XofcWLaJy/lllawIl0VH7OwNuARAzOtwLEL4=; b=kZ7opuOWugH00jaBTF8VHPch3miJOjZ0oG+cJqAnWzJIh+EaJ9TIPd3W4jFlA/ZYiuE1KaoWRa7khstDdsMNhsalqUbQ/HQXKLxObnHfzlodZSKFnZyTEv/+ZDqCk6wqooQ5zewiwE8229AzNSZO95PghuFU5DDz6MpIcSWi91M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631022120785303.5705674858682; Tue, 7 Sep 2021 06:42:00 -0700 (PDT) Received: from localhost ([::1]:46844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbMN-0002Rf-Mm for importer@patchew.org; Tue, 07 Sep 2021 09:41:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38730) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNax6-0003kD-K4 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNax0-0002fN-RA for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:51 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-125-UVIIzyf6P4mRBNh7CCmApQ-1; Tue, 07 Sep 2021 09:15:44 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 86ECE80196C; Tue, 7 Sep 2021 13:15:43 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EA155C1B4; Tue, 7 Sep 2021 13:15:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020546; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=32PbFx+XofcWLaJy/lllawIl0VH7OwNuARAzOtwLEL4=; b=Cv1cyRsNvOdMBQjTxWgvrcIooOiK5dtECBVL2Ets5JQVOoyqsFV38Bw+z79PZ2LD15AWN9 KVFpBCKMYdafw6gyGu0uHnksZLaH7w2VfAXdyrXf+5AbS2HEmRjknPOgeKn5qLoXxKa/ol 5NwBepNW4+PKHl2jLUVHeXisMlGTqm8= X-MC-Unique: UVIIzyf6P4mRBNh7CCmApQ-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 16/20] hw/s390x/s390-skeys: check if an address is valid before dumping the key Date: Tue, 7 Sep 2021 15:14:45 +0200 Message-Id: <20210907131449.493875-17-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631022121602100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Let's validate the given address and report a proper error in case it's not. All call paths now properly check the validity of the given GFN. Remove the TODO. The errors inside the getter and setter should only trigger if something really goes wrong now, for example, with a broken migration stream. Or when we forget to update the storage key allocation with memory hotplug. Signed-off-by: David Hildenbrand Acked-by: Thomas Huth Message-Id: <20210903155514.44772-12-david@redhat.com> Signed-off-by: Thomas Huth --- hw/s390x/s390-skeys.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index 56a47fe180..db73e9091d 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -18,6 +18,7 @@ #include "qapi/qmp/qdict.h" #include "qemu/error-report.h" #include "sysemu/memory_mapping.h" +#include "exec/address-spaces.h" #include "sysemu/kvm.h" #include "migration/qemu-file-types.h" #include "migration/register.h" @@ -86,6 +87,13 @@ void hmp_info_skeys(Monitor *mon, const QDict *qdict) return; } =20 + if (!address_space_access_valid(&address_space_memory, + addr & TARGET_PAGE_MASK, TARGET_PAGE_S= IZE, + false, MEMTXATTRS_UNSPECIFIED)) { + monitor_printf(mon, "Error: The given address is not valid\n"); + return; + } + r =3D skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); if (r < 0) { monitor_printf(mon, "Error: %s\n", strerror(-r)); @@ -197,11 +205,6 @@ static int qemu_s390_skeys_enabled(S390SKeysState *ss) return 1; } =20 -/* - * TODO: for memory hotplug support qemu_s390_skeys_set and qemu_s390_skey= s_get - * will have to make sure that the given gfn belongs to a memory region an= d not - * a memory hole. - */ static int qemu_s390_skeys_set(S390SKeysState *ss, uint64_t start_gfn, uint64_t count, uint8_t *keys) { --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631022487; cv=none; d=zohomail.com; s=zohoarc; b=Mgrxcm/CrEJ4kEV+M8it0Y2xEsa/ohi8AR8yLR5sYwpCNw3p0dJGYIfJXARVzQdgXK+s7liy8S1Dmos5IfPhzSdshFaVaeHELQQZ7OP0zcbVCPajFCi40c9p3XWv3pjGu8cbjmIgYrbLlI/KCSDU6HSRkwVubGu8CKliR+X1B0Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631022487; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ED1o4SQMb2cwRsy1DNx/kGHMpL8vO1uV8AYPEDjyMOs=; b=NfhOUDb7ia+ZUujjQj5Hq/2v2BOxoHcnIE/w3PafQgUTH8ehMSzDJl0JowIiinhS9BIW7ZC53JQX+YH5El5bzz9Uk4Xe3ddn7nWj01mEJWqp6jNMyajlbj0Z4zMLKt17Cy1zmo/T06JgJHAbEwawruX1cRuMCNKVFkmCcdWrt9A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631022487667914.1147761020351; Tue, 7 Sep 2021 06:48:07 -0700 (PDT) Received: from localhost ([::1]:35210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbSI-0005Xl-Mp for importer@patchew.org; Tue, 07 Sep 2021 09:48:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38760) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNax6-0003kj-Qe for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30183) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNax2-0002fn-KC for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:52 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-472-h2SNuhvGPj-OgtMaa4lGiQ-1; Tue, 07 Sep 2021 09:15:46 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 23CFC6C501; Tue, 7 Sep 2021 13:15:45 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD0B45C1B4; Tue, 7 Sep 2021 13:15:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020547; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ED1o4SQMb2cwRsy1DNx/kGHMpL8vO1uV8AYPEDjyMOs=; b=DKrBZHK87waIacFZfX4LuBwm7muUjRBm5e4gUG/SzSnyh86s0y0nrtPOoSd9/i19CjAHr3 BSScZYO0LwGj2quGcjR8Eeq1YMmmZQFqMoVgAjYvQ1/o4sc48W9twVR1B/yVwTjp0PNuzK vcqifY8DQP96e3lOCnEIz736+lcpEcA= X-MC-Unique: h2SNuhvGPj-OgtMaa4lGiQ-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 17/20] hw/s390x/s390-skeys: rename skeys_enabled to skeys_are_enabled Date: Tue, 7 Sep 2021 15:14:46 +0200 Message-Id: <20210907131449.493875-18-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631022489402100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand ... and make it return a bool instead. Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth Message-Id: <20210903155514.44772-13-david@redhat.com> Signed-off-by: Thomas Huth --- hw/s390x/s390-skeys-kvm.c | 4 ++-- hw/s390x/s390-skeys.c | 12 ++++++------ include/hw/s390x/storage-keys.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hw/s390x/s390-skeys-kvm.c b/hw/s390x/s390-skeys-kvm.c index 1c4d805ad8..3ff9d94b80 100644 --- a/hw/s390x/s390-skeys-kvm.c +++ b/hw/s390x/s390-skeys-kvm.c @@ -15,7 +15,7 @@ #include "qemu/error-report.h" #include "qemu/module.h" =20 -static int kvm_s390_skeys_enabled(S390SKeysState *ss) +static bool kvm_s390_skeys_are_enabled(S390SKeysState *ss) { S390SKeysClass *skeyclass =3D S390_SKEYS_GET_CLASS(ss); uint8_t single_key; @@ -57,7 +57,7 @@ static void kvm_s390_skeys_class_init(ObjectClass *oc, vo= id *data) S390SKeysClass *skeyclass =3D S390_SKEYS_CLASS(oc); DeviceClass *dc =3D DEVICE_CLASS(oc); =20 - skeyclass->skeys_enabled =3D kvm_s390_skeys_enabled; + skeyclass->skeys_are_enabled =3D kvm_s390_skeys_are_enabled; skeyclass->get_skeys =3D kvm_s390_skeys_get; skeyclass->set_skeys =3D kvm_s390_skeys_set; =20 diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index db73e9091d..9e994a5582 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -82,7 +82,7 @@ void hmp_info_skeys(Monitor *mon, const QDict *qdict) int r; =20 /* Quick check to see if guest is using storage keys*/ - if (!skeyclass->skeys_enabled(ss)) { + if (!skeyclass->skeys_are_enabled(ss)) { monitor_printf(mon, "Error: This guest is not using storage keys\n= "); return; } @@ -128,7 +128,7 @@ void qmp_dump_skeys(const char *filename, Error **errp) FILE *f; =20 /* Quick check to see if guest is using storage keys*/ - if (!skeyclass->skeys_enabled(ss)) { + if (!skeyclass->skeys_are_enabled(ss)) { error_setg(errp, "This guest is not using storage keys - " "nothing to dump"); return; @@ -200,9 +200,9 @@ static void qemu_s390_skeys_init(Object *obj) skeys->keydata =3D g_malloc0(skeys->key_count); } =20 -static int qemu_s390_skeys_enabled(S390SKeysState *ss) +static bool qemu_s390_skeys_are_enabled(S390SKeysState *ss) { - return 1; + return true; } =20 static int qemu_s390_skeys_set(S390SKeysState *ss, uint64_t start_gfn, @@ -250,7 +250,7 @@ static void qemu_s390_skeys_class_init(ObjectClass *oc,= void *data) S390SKeysClass *skeyclass =3D S390_SKEYS_CLASS(oc); DeviceClass *dc =3D DEVICE_CLASS(oc); =20 - skeyclass->skeys_enabled =3D qemu_s390_skeys_enabled; + skeyclass->skeys_are_enabled =3D qemu_s390_skeys_are_enabled; skeyclass->get_skeys =3D qemu_s390_skeys_get; skeyclass->set_skeys =3D qemu_s390_skeys_set; =20 @@ -277,7 +277,7 @@ static void s390_storage_keys_save(QEMUFile *f, void *o= paque) int error =3D 0; uint8_t *buf; =20 - if (!skeyclass->skeys_enabled(ss)) { + if (!skeyclass->skeys_are_enabled(ss)) { goto end_stream; } =20 diff --git a/include/hw/s390x/storage-keys.h b/include/hw/s390x/storage-key= s.h index 2888d42d0b..eb091842c8 100644 --- a/include/hw/s390x/storage-keys.h +++ b/include/hw/s390x/storage-keys.h @@ -28,7 +28,7 @@ struct S390SKeysState { =20 struct S390SKeysClass { DeviceClass parent_class; - int (*skeys_enabled)(S390SKeysState *ks); + bool (*skeys_are_enabled)(S390SKeysState *ks); int (*get_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t coun= t, uint8_t *keys); int (*set_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t coun= t, --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631021449; cv=none; d=zohomail.com; s=zohoarc; b=UHMNSEi/k+27rJ25oM7WS+JE4HqNRcf+l1EiGxVwqeLxgZUkWV6OkHETV8XMifmp/c7ap5BrPzE46ZqgiB/fZBRlWZZ5Ux4WCFDaZc456nt1zFQg6JufkrJ9OEePcnlROHYKjSz9wMFoba/t+QwcrqNoIgofz3mG3eJqS/iG/Xs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631021449; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rq2h0Jbsv6qAY22a65KCNwEpXVf48w2nQbNi+D7kbEQ=; b=EQ8hfM1CQrKV6bdfbgxtl0fT3Qx6HRD2PRm+ukhvtM8Aaq/K9vemSTt7QmdrasvtuZ11J4dZZ/xhngAdIeOnNo36V2n2avXIrSJggukksQz0rtY5q5Obrl5rIWe70K57gyOZ0JQ8iU2uvldPmB/tUJg9WM+lddOQcKoZUreK6iw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631021449185881.6609848150408; Tue, 7 Sep 2021 06:30:49 -0700 (PDT) Received: from localhost ([::1]:39238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbBY-0002ke-3k for importer@patchew.org; Tue, 07 Sep 2021 09:30:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaxB-0003sv-QM for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59143) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNax8-0002kD-Co for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:57 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-253-vOyUKt-GN_uWgSw_BExCtQ-1; Tue, 07 Sep 2021 09:15:51 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 73C39107ACCA; Tue, 7 Sep 2021 13:15:50 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BD385C3DF; Tue, 7 Sep 2021 13:15:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rq2h0Jbsv6qAY22a65KCNwEpXVf48w2nQbNi+D7kbEQ=; b=gZiM28LesTBWqENePwGBsRAPr1Q1dwDq+vyxEUEXJnCiPOcKTW2xW4wLcVYUiVtP2YJYu7 T/37ftVJMglHwM7Xvd/VTE4m9kk21B94lfXxL90n8grTB6WH6Mz36mLxYR4iSY8BYkl1NG iw3K2iJeK4HcL2oDEjzOiBQzckANlvU= X-MC-Unique: vOyUKt-GN_uWgSw_BExCtQ-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 18/20] hw/s390x/s390-skeys: lazy storage key enablement under TCG Date: Tue, 7 Sep 2021 15:14:47 +0200 Message-Id: <20210907131449.493875-19-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631021450607100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Let's enable storage keys lazily under TCG, just as we do under KVM. Only fairly old Linux versions actually make use of storage keys, so it can be kind of wasteful to allocate quite some memory and track changes and references if nobody cares. We have to make sure to flush the TLB when enabling storage keys after the VM was already running: otherwise it might happen that we don't catch references or modifications afterwards. Add proper documentation to all callbacks. The kvm-unit-tests skey tests keeps on working with this change. Signed-off-by: David Hildenbrand Reviewed-by: Thomas Huth Message-Id: <20210903155514.44772-14-david@redhat.com> Signed-off-by: Thomas Huth --- hw/s390x/s390-skeys.c | 65 ++++++++++++++++++++++++++------- include/hw/s390x/storage-keys.h | 63 ++++++++++++++++++++++++++++++++ target/s390x/mmu_helper.c | 8 ++++ target/s390x/tcg/mem_helper.c | 9 +++++ 4 files changed, 131 insertions(+), 14 deletions(-) diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index 9e994a5582..5024faf411 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -191,18 +191,45 @@ out: fclose(f); } =20 -static void qemu_s390_skeys_init(Object *obj) +static bool qemu_s390_skeys_are_enabled(S390SKeysState *ss) { - QEMUS390SKeysState *skeys =3D QEMU_S390_SKEYS(obj); - MachineState *machine =3D MACHINE(qdev_get_machine()); + QEMUS390SKeysState *skeys =3D QEMU_S390_SKEYS(ss); =20 - skeys->key_count =3D machine->ram_size / TARGET_PAGE_SIZE; - skeys->keydata =3D g_malloc0(skeys->key_count); + /* Lockless check is sufficient. */ + return !!skeys->keydata; } =20 -static bool qemu_s390_skeys_are_enabled(S390SKeysState *ss) +static bool qemu_s390_enable_skeys(S390SKeysState *ss) { - return true; + QEMUS390SKeysState *skeys =3D QEMU_S390_SKEYS(ss); + static gsize initialized; + + if (likely(skeys->keydata)) { + return true; + } + + /* + * TODO: Modern Linux doesn't use storage keys unless running KVM gues= ts + * that use storage keys. Therefore, we keep it simple for now. + * + * 1) We should initialize to "referenced+changed" for an initial + * over-indication. Let's avoid touching megabytes of data for now = and + * assume that any sane user will issue a storage key instruction b= efore + * actually relying on this data. + * 2) Relying on ram_size and allocating a big array is ugly. We should + * allocate and manage storage key data per RAMBlock or optimally u= sing + * some sparse data structure. + * 3) We only ever have a single S390SKeysState, so relying on + * g_once_init_enter() is good enough. + */ + if (g_once_init_enter(&initialized)) { + MachineState *machine =3D MACHINE(qdev_get_machine()); + + skeys->key_count =3D machine->ram_size / TARGET_PAGE_SIZE; + skeys->keydata =3D g_malloc0(skeys->key_count); + g_once_init_leave(&initialized, 1); + } + return false; } =20 static int qemu_s390_skeys_set(S390SKeysState *ss, uint64_t start_gfn, @@ -212,9 +239,10 @@ static int qemu_s390_skeys_set(S390SKeysState *ss, uin= t64_t start_gfn, int i; =20 /* Check for uint64 overflow and access beyond end of key data */ - if (start_gfn + count > skeydev->key_count || start_gfn + count < coun= t) { - error_report("Error: Setting storage keys for page beyond the end " - "of memory: gfn=3D%" PRIx64 " count=3D%" PRId64, + if (unlikely(!skeydev->keydata || start_gfn + count > skeydev->key_cou= nt || + start_gfn + count < count)) { + error_report("Error: Setting storage keys for pages with unallocat= ed " + "storage key memory: gfn=3D%" PRIx64 " count=3D%" PRI= d64, start_gfn, count); return -EINVAL; } @@ -232,9 +260,10 @@ static int qemu_s390_skeys_get(S390SKeysState *ss, uin= t64_t start_gfn, int i; =20 /* Check for uint64 overflow and access beyond end of key data */ - if (start_gfn + count > skeydev->key_count || start_gfn + count < coun= t) { - error_report("Error: Getting storage keys for page beyond the end " - "of memory: gfn=3D%" PRIx64 " count=3D%" PRId64, + if (unlikely(!skeydev->keydata || start_gfn + count > skeydev->key_cou= nt || + start_gfn + count < count)) { + error_report("Error: Getting storage keys for pages with unallocat= ed " + "storage key memory: gfn=3D%" PRIx64 " count=3D%" PRI= d64, start_gfn, count); return -EINVAL; } @@ -251,6 +280,7 @@ static void qemu_s390_skeys_class_init(ObjectClass *oc,= void *data) DeviceClass *dc =3D DEVICE_CLASS(oc); =20 skeyclass->skeys_are_enabled =3D qemu_s390_skeys_are_enabled; + skeyclass->enable_skeys =3D qemu_s390_enable_skeys; skeyclass->get_skeys =3D qemu_s390_skeys_get; skeyclass->set_skeys =3D qemu_s390_skeys_set; =20 @@ -261,7 +291,6 @@ static void qemu_s390_skeys_class_init(ObjectClass *oc,= void *data) static const TypeInfo qemu_s390_skeys_info =3D { .name =3D TYPE_QEMU_S390_SKEYS, .parent =3D TYPE_S390_SKEYS, - .instance_init =3D qemu_s390_skeys_init, .instance_size =3D sizeof(QEMUS390SKeysState), .class_init =3D qemu_s390_skeys_class_init, .class_size =3D sizeof(S390SKeysClass), @@ -341,6 +370,14 @@ static int s390_storage_keys_load(QEMUFile *f, void *o= paque, int version_id) S390SKeysClass *skeyclass =3D S390_SKEYS_GET_CLASS(ss); int ret =3D 0; =20 + /* + * Make sure to lazy-enable if required to be done explicitly. No need= to + * flush any TLB as the VM is not running yet. + */ + if (skeyclass->enable_skeys) { + skeyclass->enable_skeys(ss); + } + while (!ret) { ram_addr_t addr; int flags; diff --git a/include/hw/s390x/storage-keys.h b/include/hw/s390x/storage-key= s.h index eb091842c8..aa2ec2aae5 100644 --- a/include/hw/s390x/storage-keys.h +++ b/include/hw/s390x/storage-keys.h @@ -28,9 +28,72 @@ struct S390SKeysState { =20 struct S390SKeysClass { DeviceClass parent_class; + + /** + * @skeys_are_enabled: + * + * Check whether storage keys are enabled. If not enabled, they were n= ot + * enabled lazily either by the guest via a storage key instruction or + * by the host during migration. + * + * If disabled, everything not explicitly triggered by the guest, + * such as outgoing migration or dirty/change tracking, should not tou= ch + * storage keys and should not lazily enable it. + * + * @ks: the #S390SKeysState + * + * Returns false if not enabled and true if enabled. + */ bool (*skeys_are_enabled)(S390SKeysState *ks); + + /** + * @enable_skeys: + * + * Lazily enable storage keys. If this function is not implemented, + * setting a storage key will lazily enable storage keys implicitly + * instead. TCG guests have to make sure to flush the TLB of all CPUs + * if storage keys were not enabled before this call. + * + * @ks: the #S390SKeysState + * + * Returns false if not enabled before this call, and true if already + * enabled. + */ + bool (*enable_skeys)(S390SKeysState *ks); + + /** + * @get_skeys: + * + * Get storage keys for the given PFN range. This call will fail if + * storage keys have not been lazily enabled yet. + * + * Callers have to validate that a GFN is valid before this call. + * + * @ks: the #S390SKeysState + * @start_gfn: the start GFN to get storage keys for + * @count: the number of storage keys to get + * @keys: the byte array where storage keys will be stored to + * + * Returns 0 on success, returns an error if getting a storage key fai= led. + */ int (*get_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t coun= t, uint8_t *keys); + /** + * @set_skeys: + * + * Set storage keys for the given PFN range. This call will fail if + * storage keys have not been lazily enabled yet and implicit + * enablement is not supported. + * + * Callers have to validate that a GFN is valid before this call. + * + * @ks: the #S390SKeysState + * @start_gfn: the start GFN to set storage keys for + * @count: the number of storage keys to set + * @keys: the byte array where storage keys will be read from + * + * Returns 0 on success, returns an error if setting a storage key fai= led. + */ int (*set_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t coun= t, uint8_t *keys); }; diff --git a/target/s390x/mmu_helper.c b/target/s390x/mmu_helper.c index e2b372efd9..b04b57c235 100644 --- a/target/s390x/mmu_helper.c +++ b/target/s390x/mmu_helper.c @@ -313,6 +313,14 @@ static void mmu_handle_skey(target_ulong addr, int rw,= int *flags) skeyclass =3D S390_SKEYS_GET_CLASS(ss); } =20 + /* + * Don't enable storage keys if they are still disabled, i.e., no actu= al + * storage key instruction was issued yet. + */ + if (!skeyclass->skeys_are_enabled(ss)) { + return; + } + /* * Whenever we create a new TLB entry, we set the storage key reference * bit. In case we allow write accesses, we set the storage key change diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c index 4f9f3e1f63..0bf775a37d 100644 --- a/target/s390x/tcg/mem_helper.c +++ b/target/s390x/tcg/mem_helper.c @@ -2186,6 +2186,9 @@ uint64_t HELPER(iske)(CPUS390XState *env, uint64_t r2) if (unlikely(!ss)) { ss =3D s390_get_skeys_device(); skeyclass =3D S390_SKEYS_GET_CLASS(ss); + if (skeyclass->enable_skeys && !skeyclass->enable_skeys(ss)) { + tlb_flush_all_cpus_synced(env_cpu(env)); + } } =20 rc =3D skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); @@ -2213,6 +2216,9 @@ void HELPER(sske)(CPUS390XState *env, uint64_t r1, ui= nt64_t r2) if (unlikely(!ss)) { ss =3D s390_get_skeys_device(); skeyclass =3D S390_SKEYS_GET_CLASS(ss); + if (skeyclass->enable_skeys && !skeyclass->enable_skeys(ss)) { + tlb_flush_all_cpus_synced(env_cpu(env)); + } } =20 key =3D r1 & 0xfe; @@ -2244,6 +2250,9 @@ uint32_t HELPER(rrbe)(CPUS390XState *env, uint64_t r2) if (unlikely(!ss)) { ss =3D s390_get_skeys_device(); skeyclass =3D S390_SKEYS_GET_CLASS(ss); + if (skeyclass->enable_skeys && !skeyclass->enable_skeys(ss)) { + tlb_flush_all_cpus_synced(env_cpu(env)); + } } =20 rc =3D skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163102269453042.617926830501005; Tue, 7 Sep 2021 06:51:34 -0700 (PDT) Received: from localhost ([::1]:42476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbVd-00024Q-Gi for importer@patchew.org; Tue, 07 Sep 2021 09:51:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaxC-0003sx-Rr for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51093) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaxA-0002kf-EV for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:15:58 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-525-IOwawtooOAaaQ9Vqa0x8NA-1; Tue, 07 Sep 2021 09:15:54 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B0F126C500; Tue, 7 Sep 2021 13:15:52 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id C91F35C1B4; Tue, 7 Sep 2021 13:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020555; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/qNstejLD0mDYHxXa3IwBcq9rFlh1Qp6zgdEUJVePSE=; b=IO1AGeKXuaWcdAk317+0Ywv2jrRGhk2Heb9cW5XYMXpc1QrBU9RMcWpH1JJ/+3y46Y1uFr C7MK1hOMt8lZqIREBupG3hHsrZZa5QJcYCrRbGOFmy15wvwEaNHx4c0EazuFr860FJaxRp mJf7aYVgR8AEueIHv1ZOepHyjUsbsB0= X-MC-Unique: IOwawtooOAaaQ9Vqa0x8NA-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 19/20] s390x: Replace PAGE_SIZE, PAGE_SHIFT and PAGE_MASK Date: Tue, 7 Sep 2021 15:14:48 +0200 Message-Id: <20210907131449.493875-20-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eric Farman , Matthew Rosato , David Hildenbrand , Halil Pasic , qemu-s390x@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631022696537100001 The PAGE_SIZE macro is causing trouble on Alpine Linux since it clashes with a macro from a system header there. We already have the TARGET_PAGE_SIZE, TARGET_PAGE_MASK and TARGET_PAGE_BITS macros in QEMU anyway, so let's simply replace the PAGE_SIZE, PAGE_MASK and PAGE_SHIFT macro with their TARGET_* counterparts. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/572 Message-Id: <20210901125800.611183-1-thuth@redhat.com> Reviewed-by: Halil Pasic Reviewed-by: Matthew Rosato Reviewed-by: Eric Farman Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: David Hildenbrand Signed-off-by: Thomas Huth --- hw/s390x/s390-pci-bus.c | 10 +++++----- hw/s390x/s390-pci-inst.c | 8 ++++---- hw/s390x/sclp.c | 2 +- include/hw/s390x/s390-pci-bus.h | 5 +---- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c index 7db1c5943f..6c0225c3a0 100644 --- a/hw/s390x/s390-pci-bus.c +++ b/hw/s390x/s390-pci-bus.c @@ -330,7 +330,7 @@ static unsigned int calc_sx(dma_addr_t ptr) =20 static unsigned int calc_px(dma_addr_t ptr) { - return ((unsigned long) ptr >> PAGE_SHIFT) & ZPCI_PT_MASK; + return ((unsigned long) ptr >> TARGET_PAGE_BITS) & ZPCI_PT_MASK; } =20 static uint64_t get_rt_sto(uint64_t entry) @@ -506,7 +506,7 @@ uint16_t s390_guest_io_table_walk(uint64_t g_iota, hwad= dr addr, int8_t ett =3D 1; uint16_t error =3D 0; =20 - entry->iova =3D addr & PAGE_MASK; + entry->iova =3D addr & TARGET_PAGE_MASK; entry->translated_addr =3D 0; entry->perm =3D IOMMU_RW; =20 @@ -526,7 +526,7 @@ static IOMMUTLBEntry s390_translate_iommu(IOMMUMemoryRe= gion *mr, hwaddr addr, { S390PCIIOMMU *iommu =3D container_of(mr, S390PCIIOMMU, iommu_mr); S390IOTLBEntry *entry; - uint64_t iova =3D addr & PAGE_MASK; + uint64_t iova =3D addr & TARGET_PAGE_MASK; uint16_t error =3D 0; IOMMUTLBEntry ret =3D { .target_as =3D &address_space_memory, @@ -562,7 +562,7 @@ static IOMMUTLBEntry s390_translate_iommu(IOMMUMemoryRe= gion *mr, hwaddr addr, ret.perm =3D entry->perm; } else { ret.iova =3D iova; - ret.addr_mask =3D ~PAGE_MASK; + ret.addr_mask =3D ~TARGET_PAGE_MASK; ret.perm =3D IOMMU_NONE; } =20 @@ -868,7 +868,7 @@ static int s390_pci_msix_init(S390PCIBusDevice *pbdev) =20 name =3D g_strdup_printf("msix-s390-%04x", pbdev->uid); memory_region_init_io(&pbdev->msix_notify_mr, OBJECT(pbdev), - &s390_msi_ctrl_ops, pbdev, name, PAGE_SIZE); + &s390_msi_ctrl_ops, pbdev, name, TARGET_PAGE_SIZ= E); memory_region_add_subregion(&pbdev->iommu->mr, pbdev->pci_group->zpci_group.msia, &pbdev->msix_notify_mr); diff --git a/hw/s390x/s390-pci-inst.c b/hw/s390x/s390-pci-inst.c index 9ec277d50e..1c8ad91175 100644 --- a/hw/s390x/s390-pci-inst.c +++ b/hw/s390x/s390-pci-inst.c @@ -613,7 +613,7 @@ static uint32_t s390_pci_update_iotlb(S390PCIIOMMU *iom= mu, .iova =3D entry->iova, .translated_addr =3D entry->translated_addr, .perm =3D entry->perm, - .addr_mask =3D ~PAGE_MASK, + .addr_mask =3D ~TARGET_PAGE_MASK, }, }; =20 @@ -640,7 +640,7 @@ static uint32_t s390_pci_update_iotlb(S390PCIIOMMU *iom= mu, cache =3D g_new(S390IOTLBEntry, 1); cache->iova =3D entry->iova; cache->translated_addr =3D entry->translated_addr; - cache->len =3D PAGE_SIZE; + cache->len =3D TARGET_PAGE_SIZE; cache->perm =3D entry->perm; g_hash_table_replace(iommu->iotlb, &cache->iova, cache); dec_dma_avail(iommu); @@ -725,8 +725,8 @@ int rpcit_service_call(S390CPU *cpu, uint8_t r1, uint8_= t r2, uintptr_t ra) while (entry.iova < start && entry.iova < end && (dma_avail > 0 || entry.perm =3D=3D IOMMU_NONE)) { dma_avail =3D s390_pci_update_iotlb(iommu, &entry); - entry.iova +=3D PAGE_SIZE; - entry.translated_addr +=3D PAGE_SIZE; + entry.iova +=3D TARGET_PAGE_SIZE; + entry.translated_addr +=3D TARGET_PAGE_SIZE; } } err: diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c index edb6e3ea01..89c30a8a91 100644 --- a/hw/s390x/sclp.c +++ b/hw/s390x/sclp.c @@ -51,7 +51,7 @@ static bool sccb_verify_boundary(uint64_t sccb_addr, uint= 16_t sccb_len, uint32_t code) { uint64_t sccb_max_addr =3D sccb_addr + sccb_len - 1; - uint64_t sccb_boundary =3D (sccb_addr & PAGE_MASK) + PAGE_SIZE; + uint64_t sccb_boundary =3D (sccb_addr & TARGET_PAGE_MASK) + TARGET_PAG= E_SIZE; =20 switch (code & SCLP_CMD_CODE_MASK) { case SCLP_CMDW_READ_SCP_INFO: diff --git a/include/hw/s390x/s390-pci-bus.h b/include/hw/s390x/s390-pci-bu= s.h index 49ae9f03d3..aa891c178d 100644 --- a/include/hw/s390x/s390-pci-bus.h +++ b/include/hw/s390x/s390-pci-bus.h @@ -81,9 +81,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(S390PCIIOMMU, S390_PCI_IOMMU) #define ZPCI_SDMA_ADDR 0x100000000ULL #define ZPCI_EDMA_ADDR 0x1ffffffffffffffULL =20 -#define PAGE_SHIFT 12 -#define PAGE_SIZE (1 << PAGE_SHIFT) -#define PAGE_MASK (~(PAGE_SIZE-1)) #define PAGE_DEFAULT_ACC 0 #define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4) =20 @@ -137,7 +134,7 @@ enum ZpciIoatDtype { =20 #define ZPCI_TABLE_BITS 11 #define ZPCI_PT_BITS 8 -#define ZPCI_ST_SHIFT (ZPCI_PT_BITS + PAGE_SHIFT) +#define ZPCI_ST_SHIFT (ZPCI_PT_BITS + TARGET_PAGE_BITS) #define ZPCI_RT_SHIFT (ZPCI_ST_SHIFT + ZPCI_TABLE_BITS) =20 #define ZPCI_RTE_FLAG_MASK 0x3fffULL --=20 2.27.0 From nobody Tue May 7 00:15:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631022958577884.6787682798117; Tue, 7 Sep 2021 06:55:58 -0700 (PDT) Received: from localhost ([::1]:54296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNbZt-0001e7-So for importer@patchew.org; Tue, 07 Sep 2021 09:55:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39002) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaxG-0003z0-Mk for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:16:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51132) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNaxD-0002mF-EO for qemu-devel@nongnu.org; Tue, 07 Sep 2021 09:16:01 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-51-lSoMHB90MzO5WBwALypmcQ-1; Tue, 07 Sep 2021 09:15:55 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8AD9A8145E5; Tue, 7 Sep 2021 13:15:54 +0000 (UTC) Received: from thuth.com (unknown [10.39.194.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11C8F5C1B4; Tue, 7 Sep 2021 13:15:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631020558; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6R/ESctEN83D9gWr4ARCDqZipQXzayPnDXr4rb4Q7ho=; b=dlfFPMkvQOIjsNSzMqnlmP3tEOuxmIW4ZmmiKZGNIzUgQzb7xKPh6mhv7X0sFBIU0PDqR4 uY7znedpvTXVj0l0CHLXjnYQcaforuwqLyXVNZu6uKSsuqBY7G7OiAT7JHXR+IW3c+zNNE gQLl8p+eAMP0v02T5T0fbEuskEzU2Rs= X-MC-Unique: lSoMHB90MzO5WBwALypmcQ-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 20/20] s390x/cpumodel: Add more feature to gen16 default model Date: Tue, 7 Sep 2021 15:14:49 +0200 Message-Id: <20210907131449.493875-21-thuth@redhat.com> In-Reply-To: <20210907131449.493875-1-thuth@redhat.com> References: <20210907131449.493875-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.391, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christian Borntraeger , qemu-s390x@nongnu.org, David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631022959737100001 Content-Type: text/plain; charset="utf-8" From: Christian Borntraeger Add the new gen16 features to the default model and fence them for machine version 6.1 and earlier. Signed-off-by: Christian Borntraeger Reviewed-by: David Hildenbrand Message-Id: <20210907101017.27126-1-borntraeger@de.ibm.com> Signed-off-by: Thomas Huth --- hw/s390x/s390-virtio-ccw.c | 5 +++++ target/s390x/gen-features.c | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 4d25278cf2..61aeccb163 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -803,6 +803,11 @@ DEFINE_CCW_MACHINE(6_2, "6.2", true); static void ccw_machine_6_1_instance_options(MachineState *machine) { ccw_machine_6_2_instance_options(machine); + s390_cpudef_featoff_greater(16, 1, S390_FEAT_NNPA); + s390_cpudef_featoff_greater(16, 1, S390_FEAT_VECTOR_PACKED_DECIMAL_ENH= 2); + s390_cpudef_featoff_greater(16, 1, S390_FEAT_BEAR_ENH); + s390_cpudef_featoff_greater(16, 1, S390_FEAT_RDP); + s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAI); } =20 static void ccw_machine_6_1_class_options(MachineClass *mc) diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c index 7d85322d68..7cb1a6ec10 100644 --- a/target/s390x/gen-features.c +++ b/target/s390x/gen-features.c @@ -663,7 +663,13 @@ static uint16_t default_GEN15_GA1[] =3D { S390_FEAT_ETOKEN, }; =20 -#define default_GEN16_GA1 EmptyFeat +static uint16_t default_GEN16_GA1[] =3D { + S390_FEAT_NNPA, + S390_FEAT_VECTOR_PACKED_DECIMAL_ENH2, + S390_FEAT_BEAR_ENH, + S390_FEAT_RDP, + S390_FEAT_PAI, +}; =20 /* QEMU (CPU model) features */ =20 --=20 2.27.0