From owner-freebsd-emulation@freebsd.org Tue Dec 25 01:25:31 2018 Return-Path: Delivered-To: freebsd-emulation@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BF6C8135724C for ; Tue, 25 Dec 2018 01:25:30 +0000 (UTC) (envelope-from chuck@tuffli.net) Received: from mail-it1-x136.google.com (mail-it1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 43A3875B31 for ; Tue, 25 Dec 2018 01:25:28 +0000 (UTC) (envelope-from chuck@tuffli.net) Received: by mail-it1-x136.google.com with SMTP id g76so17301762itg.2 for ; Mon, 24 Dec 2018 17:25:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuffli-net.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=QvM9tz8KZpYIXJmjnSZZot49b3tlgXvGeOq2B/du4X0=; b=QzvDH3rIs00FZX16oMK2fhAQEjhDfC73JjBRgHZJdqZPjr8ulNqYQ8gwhoiIaM4XCY BQvCvZlsa+33OQ0eofIU882HEIyAs66QNdbLKAEETtIDMR58qhgbpdMBLOg6nTUupnHo dPwDGsKYjAtmTX5vt002iCLm/kh/g9RacSr3M4Zzuoa1iNQQFc3ktE56C0byctIc6Yz7 SNoMb3gvAH2BWzNfqFKX0Mux5J/qil3QNOiws+/nQtLYeTCKymLWw9LMrwHUSawmPZLi h3O+lUybzq49WVzg8j9NX5WuC2ypQV4VXe6xqmteqtYup07fXvh69cWTU1bbTDFZ+oU3 4Gdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=QvM9tz8KZpYIXJmjnSZZot49b3tlgXvGeOq2B/du4X0=; b=RyHhRqUdecAJX8e2xArnOSJGdYX/+7nnRLegQDKcSUqRSPulr2+DYPafKkrs7JTyxc y10Yo2auMWqq2wvTNORY4xULZ490xeTrxBGhdeDLQpOt5QG3yWw3TRHnpdzOkoe3tYFo 2+vOtZDFg/fvthAf5jS54/GS5azBrY19gY+jdcd141ihrMun2WM1X0Tn7fywAD8iM/Gs zcUoZa5EQFV/2RNuqOzJJvtgQyxeqQEoD/qYQseEkxrbyjQmvp16lYtxhnHTUxLh6jij EUFY6sRKDMhYnojlTJ/HJdZ+ylYXAkaXJEbTsx2Ncnc4xPrGQAvBAETpNy3+UtLF1gS0 YhuQ== X-Gm-Message-State: AA+aEWbHupNOoYlPwaAhShNuanGzHRPD2/z66Fn50TEMNwvDVzvVoVMn HYIC9U58yPcwmuPPtfi3J+UMZqIEhYAHBMQ0fr9kKJ9B X-Google-Smtp-Source: AFSGD/VZkQC4VSL0VLw2Im2dxWGNK/0gUhGUAnR5Nj0qFreCWoK8ms4XL6p/s1t6rlzeF3kaCmDqzIeQqJDsRIwIjf0= X-Received: by 2002:a02:95e4:: with SMTP id b91mr8944556jai.15.1545701128028; Mon, 24 Dec 2018 17:25:28 -0800 (PST) MIME-Version: 1.0 From: Chuck Tuffli Date: Mon, 24 Dec 2018 17:24:39 -0800 Message-ID: Subject: core dumps running in bhyve To: freebsd-emulation@freebsd.org, FreeBSD Hackers Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 43A3875B31 X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=tuffli-net.20150623.gappssmtp.com header.s=20150623 header.b=QzvDH3rI; spf=permerror (mx1.freebsd.org: domain of chuck@tuffli.net uses mechanism not recognized by this client) smtp.mailfrom=chuck@tuffli.net X-Spamd-Result: default: False [-5.50 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[tuffli-net.20150623.gappssmtp.com:s=20150623]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-emulation@freebsd.org]; DMARC_NA(0.00)[tuffli.net]; TO_MATCH_ENVRCPT_SOME(0.00)[]; R_SPF_PERMFAIL(0.00)[]; MX_GOOD(-0.01)[alt1.aspmx.l.google.com,aspmx.l.google.com,aspmx3.googlemail.com,aspmx2.googlemail.com,aspmx5.googlemail.com,alt2.aspmx.l.google.com,aspmx4.googlemail.com]; RCPT_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[tuffli-net.20150623.gappssmtp.com:+]; RCVD_IN_DNSWL_NONE(0.00)[6.3.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; NEURAL_HAM_SHORT(-0.97)[-0.974,0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; RCVD_COUNT_TWO(0.00)[2]; IP_SCORE(-2.22)[ip: (-7.67), ipnet: 2607:f8b0::/32(-1.85), asn: 15169(-1.48), country: US(-0.08)] X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Dec 2018 01:25:31 -0000 Using the latest bhyve, I'm seeing core dumps in the guest when running: nvmecontrol identify nvme0 against the emulated NVMe drive. The location of the core dump changes from run to run, but I suspect the root cause is a memory corruption caused by the transfer of the Identify data (4KB) back to the guest. This transfer of data is actually a memcpy to an address returned from vm_map_gpa() based on the physical address provided by the guest. Based on the signature of one of the core dumps, I modified nvmecontrol to always pass a 4KB aligned buffer to the driver instead of the (typically) unaligned address of the structure on the stack. With this change, nvmecontrol in the guest no longer core dumps. What I don't understand is why this changes the behavior. Do the addresses passed to vm_map_gpa() need to be page aligned? Or did moving the memory location from the stack to the heap merely mitigate what is corrupted? Thoughts? --chuck