From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0C96C388F7 for ; Thu, 22 Oct 2020 13:21:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 804D32417D for ; Thu, 22 Oct 2020 13:21:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603372906; bh=imaYIfsDwMHkkiZz0txYafwsmOxZZcka5WzSZDZvOMc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=2cd3mzEsZ3FksTXH0MB/Lb/rEqMC3UR71cMloJm6Hfp5L3JR9bfql06YRxC7SFN3+ JwsLmG3MjL4Dy5piicBABPqfGJjb/cdQhKUZd6XetI7lzb0KsYxUPOvYlTVJ31mUNS P7/CxdkcOMJzQVDkO3Rezmp0GiqToYBx1Mz/NST8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2506543AbgJVNVp (ORCPT ); Thu, 22 Oct 2020 09:21:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:49816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439419AbgJVNVp (ORCPT ); Thu, 22 Oct 2020 09:21:45 -0400 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ED8BB2417D; Thu, 22 Oct 2020 13:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603372904; bh=imaYIfsDwMHkkiZz0txYafwsmOxZZcka5WzSZDZvOMc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=hlaBwn96/Z/ocnQHcDHthDlc+R/uh2SQ+r8oYdrOWoXmOwTgeajdlKcOBxPZxCHu5 p/secp8SSjZgPNwWLcFqIBTQHqHRkI3CRfZOWZGm1nLnRBeSBile47AmBzRDGersCn auRhckr6/qmFJfDOSgKM+K2hbkc5iy8C0zfM+kyA= Date: Thu, 22 Oct 2020 22:21:40 +0900 From: Masami Hiramatsu To: Borislav Petkov Cc: x86-ml , Joerg Roedel , lkml Subject: Re: [RFC] Have insn decoder functions return success/failure Message-Id: <20201022222140.f46e6db1243e05fdd049b504@kernel.org> In-Reply-To: <20201022093044.GA29222@zn.tnic> References: <20201020120232.GD11583@zn.tnic> <20201020232700.5510c236d810b7f8a66779e2@kernel.org> <20201020143746.GG11583@zn.tnic> <20201021095013.d82637f84af564ae4363189d@kernel.org> <20201021092750.GA4050@zn.tnic> <20201021232613.e40c1daef4b567e0e29044a4@kernel.org> <20201021164558.GB4050@zn.tnic> <20201022163100.1139b28220da4eafb5e70fcc@kernel.org> <20201022093044.GA29222@zn.tnic> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 22 Oct 2020 11:30:44 +0200 Borislav Petkov wrote: > On Thu, Oct 22, 2020 at 04:31:00PM +0900, Masami Hiramatsu wrote: > > No, insn_get_length() implies it decodes whole of the instruction. > > (yeah, we need an alias of that, something like insn_get_complete()) > > That's exactly what I'm trying to point out: the whole API is not > entirely wrong - it just needs a better naming and documentation. Now, > the implication that getting the length of the insn will give you a full > decode is a totally internal detail which users don't need and have to > know. Ok, what names would you like to suggest? insn_get_complete()? > > I need insn.length too. Of course we can split it into 2 calls. But > > as I said, since the insn_get_length() implies it decodes all other > > parts, I just called it once. > > Yes, I have noticed that and wrote about it further on. The intent was > to show that the API needs work. > > > Hm, it is better to call insn_get_immediate() if it doesn't use length later. > > Ok, so you see the problem. This thing wants to decode the whole insn - > that's what the function is called. But it reads like it does something > else. > > > Would you mean we'd better have something like insn_get_until_immediate() ? > > > > Since the x86 instruction is CISC, we can not decode intermediate > > parts. The APIs follows that. If you are confused, I'm sorry about that. > > No, I'm not confused - again, I'd like for the API to be properly > defined and callers should not have to care which parts of the insn they > need to decode in order to get something else they actually need. Sorry, I can not get what you point. We already have those APIs, extern void insn_init(struct insn *insn, const void *kaddr, int buf_len, int x86_64); extern void insn_get_prefixes(struct insn *insn); extern void insn_get_opcode(struct insn *insn); extern void insn_get_modrm(struct insn *insn); extern void insn_get_sib(struct insn *insn); extern void insn_get_displacement(struct insn *insn); extern void insn_get_immediate(struct insn *insn); extern void insn_get_length(struct insn *insn); As I agreed, that we may need an alias of insn_get_length(). But it seems clear to me, if you need insn.immediate, you must call insn_get_immediate(). > So the main API should be: insn_decode_insn() or so and it should give > you everything you need. > > If this succeeds, you can go poke at insn. and you know you have > valid data there. Ah, so you meant that we don't need such a different insn_get_* APIs, but a single insn_decode() API, which will decode all fields. (IOW, alias of insn_init() and insn_get_length(), right?) > If there are specialized uses, you can call some of the insn_get_* > helpers if you're not interested in decoding the full insn. OK, agreed. > > But if simply calling insn_decode_insn() would give you everything and > that is not that expensive, we can do that - API simplicity. I rather like simple "insn_decode()" function, no need to repeat insn again. int insn_decode(struct insn *insn, const void *kaddr, int buf_len, bool x86_64); > > What I don't want to have is calling insn_get_length() or so and then > inspecting the opcode bytes because that's totally non-transparent. OK, I agreed. Thank you, > > Thx. > > -- > Regards/Gruss, > Boris. > > https://people.kernel.org/tglx/notes-about-netiquette -- Masami Hiramatsu