From patchwork Tue Aug 26 14:21:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 36037 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oi0-f70.google.com (mail-oi0-f70.google.com [209.85.218.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8DF842054F for ; Tue, 26 Aug 2014 14:23:25 +0000 (UTC) Received: by mail-oi0-f70.google.com with SMTP id u20sf75837656oif.5 for ; Tue, 26 Aug 2014 07:23:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mime-version:in-reply-to:references :date:message-id:subject:from:to:cc:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=GtskoYfcOnR4NWeVwS9tKVy6DvJ6eWrmiw+2z2bBgIA=; b=MS+z6DOQ3j4fr+OGeEw4R7qGmSzYOZ/fY9REPg2OcRWc9Is6/15B5v/AIRx+JJHSA2 WGtb7qsAThp6RcPmJ5iEZj0nMC/pVLmo5j6g4Kn4fxJccXfBm31Z7D0IhSBfYjHMUcf9 qYzq1k6UsXw1AjEexQ60F3v7EFKOZSlcUxn9+4Snu1NEIh9UzAeTqS5Pb0gBRIosFfDK ElPxrTf2uiKdXPTabV/ImY4J6EkPmRDQcrRlep/vdjhKB4+qjdigTMOOoQeQ6QLfDBca dIJt3Kh7K7rFzmBtRkk/RVYlLqn+4v7G4/lr4ZLapECMMnl7cOHiX7wvpi5pRqCuBaBH VR4g== X-Gm-Message-State: ALoCoQnHo/kNouBVRjsXqjVG8JdzkKalmZzgkVRFA2kDXTtPZkwW1Sxr2PT53Y4V2PwU1xIYcLDP X-Received: by 10.182.45.197 with SMTP id p5mr18157742obm.2.1409063005171; Tue, 26 Aug 2014 07:23:25 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.94.87 with SMTP id f81ls2580580qge.65.gmail; Tue, 26 Aug 2014 07:23:24 -0700 (PDT) X-Received: by 10.236.137.195 with SMTP id y43mr2040886yhi.114.1409063003898; Tue, 26 Aug 2014 07:23:23 -0700 (PDT) Received: from mail-yh0-f43.google.com (mail-yh0-f43.google.com [209.85.213.43]) by mx.google.com with ESMTPS id p27si2538965yhp.143.2014.08.26.07.23.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 26 Aug 2014 07:23:23 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.213.43 as permitted sender) client-ip=209.85.213.43; Received: by mail-yh0-f43.google.com with SMTP id 29so11825861yhl.2 for ; Tue, 26 Aug 2014 07:23:23 -0700 (PDT) X-Received: by 10.220.97.5 with SMTP id j5mr24326824vcn.16.1409063003805; Tue, 26 Aug 2014 07:23:23 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp203365vcb; Tue, 26 Aug 2014 07:23:23 -0700 (PDT) X-Received: by 10.66.122.99 with SMTP id lr3mr37926868pab.0.1409063002754; Tue, 26 Aug 2014 07:23:22 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [198.137.202.9]) by mx.google.com with ESMTPS id z5si4846407pdp.24.2014.08.26.07.23.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Aug 2014 07:23:22 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=198.137.202.9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XMHdG-0007H7-Qv; Tue, 26 Aug 2014 14:21:58 +0000 Received: from mail-lb0-f181.google.com ([209.85.217.181]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XMHcr-0005y5-JE for linux-arm-kernel@lists.infradead.org; Tue, 26 Aug 2014 14:21:34 +0000 Received: by mail-lb0-f181.google.com with SMTP id 10so1426062lbg.40 for ; Tue, 26 Aug 2014 07:21:09 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.183.162 with SMTP id en2mr26216684lbc.51.1409062869573; Tue, 26 Aug 2014 07:21:09 -0700 (PDT) Received: by 10.112.247.70 with HTTP; Tue, 26 Aug 2014 07:21:09 -0700 (PDT) In-Reply-To: <20140826131339.GO23445@arm.com> References: <1409048930-21598-1-git-send-email-punit.agrawal@arm.com> <1409048930-21598-4-git-send-email-punit.agrawal@arm.com> <20140826131339.GO23445@arm.com> Date: Tue, 26 Aug 2014 16:21:09 +0200 Message-ID: Subject: Re: [PATCH 3/6] arm64: Add support for hooks to handle undefined instructions From: Ard Biesheuvel To: Will Deacon X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140826_072133_874040_22FB6288 X-CRM114-Status: GOOD ( 19.77 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.217.181 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.217.181 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Catalin Marinas , Punit Agrawal , "linux-arm-kernel@lists.infradead.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.213.43 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 On 26 August 2014 15:13, Will Deacon wrote: > Hi Punit, > > On Tue, Aug 26, 2014 at 11:28:47AM +0100, Punit Agrawal wrote: >> Add support to register hooks for undefined instructions. The handlers >> will be called when the undefined instruction and the processor state >> (as contained in pstate) match criteria used at registration. >> >> Note: The patch only deals with ARM instruction encodings and needs >> fixing to handle thumb instructions as well. > > [...] > >> +static int call_undef_hook(struct pt_regs *regs) >> +{ >> + struct undef_hook *hook; >> + unsigned long flags; >> + u32 instr; >> + int (*fn)(struct pt_regs *regs, u32 instr) = NULL; >> + void __user *pc = (void __user *)instruction_pointer(regs); >> + >> + /* >> + * Currently, undefined instruction patching is only supported >> + * for user mode. Also, as we're not emulating any thumb >> + * instructions lets not add thumb instruction decoding until >> + * it is needed. >> + */ >> + if (!compat_user_mode(regs) || compat_thumb_mode(regs)) >> + return 1; > > What do you mean by `undefined instruction patching'? I don't see anything > in the mechanism that means this can't be reused for kernel code, then we > just register the SWP emulation hook for userspace only using the mode (like > we do for kgdb). > You need this patch in order to be able to return from an undef exception taken in EL1: --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -287,7 +287,9 @@ el1_undef: */ enable_dbg mov x0, sp - b do_undefinstr + bl do_undefinstr + + kernel_exit 1 el1_dbg: /* * Debug exception handling