From patchwork Wed Mar 28 07:39:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 10312455 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 90FD360467 for ; Wed, 28 Mar 2018 07:39:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E13128A0F for ; Wed, 28 Mar 2018 07:39:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7269A2940F; Wed, 28 Mar 2018 07:39:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E22328A0F for ; Wed, 28 Mar 2018 07:39:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753478AbeC1Hjx (ORCPT ); Wed, 28 Mar 2018 03:39:53 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58542 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753064AbeC1Hjv (ORCPT ); Wed, 28 Mar 2018 03:39:51 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 97FC14067EF0; Wed, 28 Mar 2018 07:39:50 +0000 (UTC) Received: from thh440s.str.redhat.com (dhcp-192-189.str.redhat.com [10.33.192.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9CBF10B2B38; Wed, 28 Mar 2018 07:39:49 +0000 (UTC) From: Thomas Huth To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Cc: kvm@vger.kernel.org, David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 2/8] s390x: Add privileged operation exceptions handling Date: Wed, 28 Mar 2018 09:39:38 +0200 Message-Id: <1522222784-7709-3-git-send-email-thuth@redhat.com> In-Reply-To: <1522222784-7709-1-git-send-email-thuth@redhat.com> References: <1522222784-7709-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 28 Mar 2018 07:39:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 28 Mar 2018 07:39:50 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Janosch Frank A huge part of the emulated instructions are privileged and result in an operation exception, when executed in problem state. To be able to test this, we introduce the enter_pstate function, that sets the cpu to the problem state. Also we extend the interrupt handler, so it resets us to supervisor mode again, when we hit the privileged operation exception. Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth Reviewed-by: David Hildenbrand Signed-off-by: Thomas Huth --- lib/s390x/asm/arch_def.h | 10 ++++++++++ lib/s390x/interrupt.c | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h index 620dca4..b67afac 100644 --- a/lib/s390x/asm/arch_def.h +++ b/lib/s390x/asm/arch_def.h @@ -16,6 +16,7 @@ struct psw { }; #define PSW_MASK_DAT 0x0400000000000000UL +#define PSW_MASK_PSTATE 0x0001000000000000UL struct lowcore { uint8_t pad_0x0000[0x0080 - 0x0000]; /* 0x0000 */ @@ -209,4 +210,13 @@ static inline void load_psw_mask(uint64_t mask) : "+r" (tmp) : "a" (&psw) : "memory", "cc" ); } +static inline void enter_pstate(void) +{ + uint64_t mask; + + mask = extract_psw_mask(); + mask |= PSW_MASK_PSTATE; + load_psw_mask(mask); +} + #endif diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c index 67d581b..56c7603 100644 --- a/lib/s390x/interrupt.c +++ b/lib/s390x/interrupt.c @@ -44,6 +44,13 @@ void check_pgm_int_code(uint16_t code) static void fixup_pgm_int(void) { switch (lc->pgm_int_code) { + case PGM_INT_CODE_PRIVILEGED_OPERATION: + /* Normal operation is in supervisor state, so this exception + * was produced intentionally and we should return to the + * supervisor state. + */ + lc->pgm_old_psw.mask &= ~PSW_MASK_PSTATE; + break; case PGM_INT_CODE_SEGMENT_TRANSLATION: case PGM_INT_CODE_PAGE_TRANSLATION: case PGM_INT_CODE_TRACE_TABLE: